use strict; use warnings; my $pattern = shift; my $target = 'aBC'; my $regex; eval "\$regex = qr ($pattern)"; print $regex, "\n"; print $target =~ $regex ? "$pattern Worked!\n" : "$pattern Failed!\n";
The eval line interpolates the pattern before it is turned into a regex by qr.
Also consider $pattern =~ s/(.*)/qq(qq($1))/ee; as a way of doing the interpolation without using a direct eval. This method can still be poisoned using a carefully crafted regex.
In reply to Re: qr/string/ is not the same as qr/$var/ ?
by inman
in thread qr/string/ is not the same as qr/$var/ ?
by grinder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |