Your skill will accomplish what the force of many cannot |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
The qr// is more readable in that it clearly signifies to the reader that the thing inside is assumed to be used as a regexp later on. The other thing that makes this more readable in some cases is that the stuff inside the qr// is treated as a regexp, not as a single quoted string with regards to escaping special characters. There is a huge difference between $part = qr/\\d/; and $part = q/\\d/; ! The first will eventually match a backslash followed by letter d, the second will match a digit. Are you sure you will remember to quadruple your backslashes if you want to match a literal backslash? And regarding the speed of constructed pattern ... maybe you stopped one qr// too soon. Instead of building the ultimate pattern at the point it was used, you should have built it just once at the same place you've defined the parts and then used just if ($var =~ $built_regexp) or $var =~ s/$built_regexp/replacement/;. Maybe. I haven't seen your code. Jenda In reply to Re^6: Common Perl Pitfalls
by Jenda
|
|