in reply to qr/string/ is not the same as qr/$var/ ?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: qr/string/ is not the same as qr/$var/ ?
by deibyz (Hermit) on Apr 19, 2005 at 10:33 UTC |