in reply to How do I pass $1 to s///?
Your $1 gets interpolated too early. What you really need is a templating system, but you can use the following in the meanwhile:
sub foo { (my $text = $_[0]) =~ s/$_[1]/eval $_[2]/e; print $text; } foo("This is test 1\n", qr/test (.*)/, '"fish $1"');
(Insert notice of hazards of using eval EXPR here.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do I pass $1 to s///?
by Anonymous Monk on Jan 06, 2006 at 19:19 UTC | |
by ikegami (Patriarch) on Jan 06, 2006 at 19:32 UTC | |
by Anonymous Monk on Jan 06, 2006 at 20:10 UTC | |
by ikegami (Patriarch) on Jan 06, 2006 at 20:17 UTC | |
by Anonymous Monk on Jan 06, 2006 at 21:03 UTC | |
| |
|
Re^2: How do I pass $1 to s///?
by Anonymous Monk on Jan 06, 2006 at 17:19 UTC | |
by ikegami (Patriarch) on Jan 06, 2006 at 17:25 UTC | |
|
Re^2: How do I pass $1 to s///?
by Anonymous Monk on Jan 06, 2006 at 17:07 UTC | |
by ikegami (Patriarch) on Jan 06, 2006 at 17:23 UTC | |
by Happy-the-monk (Canon) on Jan 06, 2006 at 17:24 UTC |