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.
  • I sat in a Perl Script Security talk, noting that /^[a-z]+$/ on the slides would erroneously match foo\n

    Is using [:lower:] the appropriate approach? Just curious.

    • The correct thing is to use \z:
      $_ = "blah\n";
      print "dollar\n" if /^[a-z]+$/;
      print "z\n" if /^[a-z]+\z/;
      __END__
      dollar
      I don't quite like the \a or \z modifiers. They seem a bit funky to me.

      I tend to solve this problem by getting rid of leading and trailing whitespace with something like:

      my %params = map { $_ => trim($cgi->param($_)) } qw(var_a var_b var_c);

      sub trim {
        my $str = shift;
        if ($str) {
           $str =~ s/^\s+//;
           $str =~ s/\s+$//;
        }
        $str;
      }
      This also means the user doesn't get tripped up by an extra space at the end of their username etc.