in reply to Re^2: hard-to-understand taint error
in thread hard-to-understand taint error

That regex won't capture files with UC letters

#!/usr/bin/perl use warnings; use strict; # 744661 my @var = [ 'foo.Bar', 'for.bar', ]; for my $var(@var) { if ( $var =~ /^(__[-!#.0-9@-Z_a-z]+)$/ ) { print "\$var: $var\n"; } else { print "no match!\n"; } }

If you're concerned about files like "foo.Bar", use the /i modifier.

Replies are listed 'Best First'.
Re^4: hard-to-understand taint error
by ikegami (Patriarch) on Feb 18, 2009 at 14:27 UTC
    Not true. [@-Z] is an obfuscated way of writing [\@A-Z]. Your test fails for two reasons:
    • Your array only contains one element and it's an array reference.
    • Your file names don't start with __.
      Aaaargh!

      How do I downvote / borg myself?

      However (conveniently bypassing the requirement for names beginning with __):

      #!/usr/bin/perl use warnings; use strict; # 744661 my @var = ( 'foo.Bar', 'for.bar', ); for my $var(@var) { print "Before regex, \$var: $var \n"; if ( $var =~ /^([-!#.0-9@-Z_a-z]+)$/ ) { print "\$var: $var\n"; } else { print "no match!\n"; } }

      produces:

      Before regex, $var: foo.Bar no match! Before regex, $var: for.bar $var: for.bar

      whereas using /i in the regex at line 12:

      Before regex, $var: foo.Bar $var: foo.Bar Before regex, $var: for.bar $var: for.bar

      leaving me to wonder about the "shorthand."

        Oops. It took me a while to figure out that you were using square brackets. By the time I figured that out, it looks like I had changed from [@-Z] (interpolation of var @- plus "Z") to [\@-Z] (short for [\@A-Z]).

        In ASCII-based encodings, "@" is "\x40", the character before "A".