SPUG: regexp s/// issues with backreferences stored in a scalar string
mike
mike206 at gmail.com
Wed Feb 1 13:31:19 PST 2006
the comments pretty much speak for themselves.
i did that so anyone interested can replicate the problem with a cut and
paste.
---- begin ----
#!/usr/bin/perl
-w
# here's a
regexp
my $regexp = q{(abcd)(efg)};
# here's a substitution
pattern
# note the single q{} to block it from
interpolating
my $suss = q{$2 $1};
# here's a
string
my $string = q{abcdefgh};
# run the regexp and
putout
$string =~ s/$regexp/$suss/;
print $string."\n";
############################ prints '$2 $1h'
# now try again but hardcode the backreferences in the substitution
$string = q{abcdefgh};
$string =~ s/$regexp/$2 $1/;
print $string."\n";
################### prints 'efg abcdh' , as it should
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/spug-list/attachments/20060201/c50d8ae8/attachment.html
More information about the spug-list
mailing list