Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • My guess is that sometimes, $country is undef. And because it might be, the author writes horribly perverted code just to avoid getting an irrelevant warning message. This is the downside of warnings.

    And given that, I'd have written this code as: $country = $country eq 'gbr' ? '' : uc $country; See how much clearer it is when you stop worrying about stupid warnings? Don't be pedantic about warnings. Stop using them when they make your code look ugly. (/end rant).

    --
    • Randal L. Schwartz
    • Stonehenge
    • My interpretation....was that $country wasn't dealing with definedness, but was instead determining whether or not to use brackets. If there's nothing there, "[]" might look stupid, so you don't want to put the brackets; and if it's 'gbr', you don't want anything there for whatever reason.
    • If it’s really just undef, then an or '' in the appropriate spot would suffice – no need for convolution.

      That said, almost all my code starts like so:

      use warnings;
      no warnings qw( once qw );
      • I looked in the perllexwarn pod and it just shows "once" in the hierarchy. What exactly does that do?
        • Sometimes you refer to a variable in another file:

          $CGI::DISABLE_UPLOADS = 1;

          That snippet will prevent a DOS on your server from folks repeatedly uploading files. However, it's probably only in your code once and warnings will issue a warning about it which you can disable with no warnings 'once'.

          It's designed, however, for cases where you declare something and never use it again. That's probably cruft that you don't actually want in your code (or worse, you declare something but refer to it by the

        • It suppresses warnings like this:

          Name "main::x" used only once: possible typo at -e line 1.

          This is a poor man’s use strict 'vars': the idea is that if you used a variable just once, it’s probably because you meant to use another variable but mistyped its name. However, you will get this warning only about package variables, not about my lexicals.

          These days, I generally use package variables only when I need to change a global setting in some module I’m using, such as the $CGI::DISAB