in reply to Re^2: Variable substitute and capturing
in thread Variable substitute and capturing
I guess escaping $search is better though so that each eval call is dynamic on both ends (search & replace)..use strict; use warnings; my $s = "foobar"; my $search=qr/(foo)(bar)/; my $replace="\$1-\$2"; my $perl = "\$s =~ s/$search/$replace/"; warn $perl; eval $perl; print $s; __OUTPUT__ $s =~ s/(?-xism:(foo)(bar))/$1-$2/ at -e line 1. foo-bar
perl -le '$s = foobar; $search=qr/(foo)(bar)/; $replace="\$1-\$2"; $s +=~ s/$search/eval $replace/e; print $s'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Variable substitute and capturing
by ikegami (Patriarch) on Jan 16, 2006 at 17:08 UTC |