SeekerOKnowledge has asked for the wisdom of the Perl Monks concerning the following question:
How do I get $2 to be replaced correctly given that $replace is defined previous to the substitution? I was unsuccessful when using eval.#!/usr/bin/perl my $s0 = "red apple"; my $s1 = $s0; print "s0 = $s0\n"; my $k = 0; my $pattern = qr/(.)ed/; $s0 =~ s/$pattern/++$k && "$1osy"/ge; print "$k change(s)\n"; print "s0 = $s0\n"; $k = 0; $pattern = qr/r(.)(.)/; my $replace = '$2ead'; $s1 =~ s/$pattern/++$k && $replace/ge; print "$k change(s)\n"; print "s1 = $s1\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: defering substitution within double-quoted strings?
by sauoq (Abbot) on Sep 04, 2003 at 19:54 UTC | |
by SeekerOKnowledge (Initiate) on Sep 04, 2003 at 20:53 UTC | |
|
Re: defering substitution within double-quoted strings?
by chromatic (Archbishop) on Sep 04, 2003 at 20:31 UTC | |
|
Re: defering substitution within double-quoted strings?
by hardburn (Abbot) on Sep 04, 2003 at 19:54 UTC |