in reply to qr/string/ is not the same as qr/$var/ ?
Is there danger here that I don't see?use strict; use warnings; my $scary_regex = shift; $scary_regex =~ tr/\cA//d; # There are now no control-As in the string, # so I can safely use them as delimiters my $safe_pat = eval "qq\cA$scary_regex\cA"; my $safe_reg = qr/$safe_pat/; print "Safe pat is $safe_pat; reg is $safe_reg\n";
Update: Pustular Postulant pointed out that you could go straight to the regex, rather than having the intermediate $safe_pat string (just use qr instead of qq). When I was putting it together, something told me that wasn't safe, but I think it is.
Also note that \cA on the input works fine, if you actually want control-A in your pattern.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: qr/string/ is not the same as qr/$var/ ?
by Roy Johnson (Monsignor) on Apr 20, 2005 at 19:19 UTC | |
by tlm (Prior) on Apr 20, 2005 at 20:09 UTC | |
by Roy Johnson (Monsignor) on Apr 20, 2005 at 20:25 UTC |