The advantage here is that you don't end up re-evaluating the function code each time, just the function call.sub safeswitch { my @P = (undef,$1,$2,$3,$4,$5,$6,$7,$8,$9); $_[0] =~ s/\$(\d)/$P[$1]/g; $_[0]; } my $str = "abcdefghijafjafjkagjakg"; my $pat = '(a.)'; my $repl = '$1 '; $str =~ s/$pat/safeswitch($repl)/eg; print $str,$/;
In reply to Re: $1 in variable regex replacement string
by tadman
in thread $1 in variable regex replacement string
by dvergin
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |