Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
With the intention of replaceing "test n" with "fish n" using backreferncing. But can I get it to work!? I've tried replacing it with "fish $1", "fish \$1", "fish \\$1" and even "fish \\\$1"! Sadly nothing yields the result I'm after. Could anyone explain why, and how I should do what I'm trying to do?# foo(text, regexp, replacement) # print text with replacements sub foo { my $text; ($text = $_[0]) =~ s/$_[1]/$_[2]/; print $text; } foo("This is test 1\n", "test (.*)", "fish $1");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I pass $1 to s///?
by ikegami (Patriarch) on Jan 06, 2006 at 16:56 UTC | |
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 17:19 UTC | |
by ikegami (Patriarch) on Jan 06, 2006 at 17:25 UTC | |
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 | |
|
Re: How do I pass $1 to s///?
by Happy-the-monk (Canon) on Jan 06, 2006 at 16:54 UTC | |
by ikegami (Patriarch) on Jan 06, 2006 at 17:42 UTC | |
by tweetiepooh (Hermit) on Jan 06, 2006 at 17:09 UTC | |
by Anonymous Monk on Jan 06, 2006 at 17:03 UTC |