
eWish
User
Aug 8, 2007, 7:39 PM
Views: 1713
|
|
Re: [ericm] replacement with backreference
|
|
|
I may be missing what you are trying to do here. my $pattern = $field[0]; my $replacement = $field[1]; my $test = $field[0]; if ($test =~ /^$pattern$/) { # $& holds the entire regex match. my $test1 =~ s/$&/$replacement/; # Or you could use $1 if you would like. my $test2 =~ s/$1/$replacement/; print $test1, "\n"; print $test2, "\n"; } else { print "Did not find a match for $pattern in $test"; }
(This post was edited by eWish on Aug 8, 2007, 7:46 PM)
|