in reply to regex optimization
A few comments. First {1} is useless as a literal char in a regex means {1} of. Next adding \s* at the end allows trailing whitepspace which is common. Next - it is better to specify what is legal than what is illegal as your regex will probably not catch all the nasty chars. Just allow through what you need by adding them to the $valid class. Using this method you know all the chars that are valid. If you drop the syntax check you can do the match/untaint in one line. Oh and you don't need to \ the ; as the 12 regex metachars are $^*()+{[|\.? Finally the /g does nothing as you are insisting on a match from the begining of the line to a newline (which in this case will be the end of the line - unless you have been messing with $/ :-)
my $valid = qr/[\w\s]/; while (<DATA>){ # grab: ween{(commands)} if (/^ween\s*\{\s*($valid+;)\s*\}\s*$/) { my $cmd = $1; print "Found $cmd\n"; } else { print "$0: Illegal chars or incorrect syntax!\n"; print "Line: $_\n"; } } __DATA__ ween { foo bar; } ween { del *.*; }
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|