I like Gramp's solution: simple, elegant and efficient. Too often people automatically go for a regex when the good old tr operator is a better choice.
Due to my unfortunate golfing past, I can't restrain myself from noting that, if you are feeling in a silly mood, you could replace his simple and clear line:
with this silly one:print "Matched $_\n" if tr/pP// && tr/eE// && tr/rR// && tr/lL//;
Deparse confirming their equivalence:y&pP&&&&y&eE&&&&y&rR&&&&y&lL&&&&print"Matched $_\n";
# cat sensible.pl print "Matched $_\n" if tr/pP// && tr/eE// && tr/rR// && tr/lL//; # perl -MO=Deparse sensible.pl print "Matched $_\n" if tr/Pp// and tr/Ee// and tr/Rr// and tr/Ll//; sensible.pl syntax OK # cat silly.pl y&pP&&&&y&eE&&&&y&rR&&&&y&lL&&&&print"Matched $_\n"; # perl -MO=Deparse silly.pl print "Matched $_\n" if tr/Pp// and tr/Ee// and tr/Rr// and tr/Ll//; silly.pl syntax OK
In reply to Re^2: A Quick Regex Question
by eyepopslikeamosquito
in thread A Quick Regex Question
by chinamox
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |