in reply to $1 in variable regex replacement string
Update: sorry, I missed jsprat's previous answer, so this post is a poor dupe :-)
this may not be properly what you're looking for, but Dominus's first Quiz of the Week was very similar.
the goal was to:
Write a subroutine, 'subst', which gets a string argument, $s. It should search $s and replace any occurrences of "$1" with the current value of $1, any occurrences of "$2" with the current value of $2, and so on.you can find the original question along with MJD's solution and discussion here.For example, if $1, $2, and $3 happen to be "dogs", "fish" and "carrots", then
subst('$2, $1 and $3')should return"fish, dogs, and carrots"
hope this helps (or entertains at least :-).
oh, by the way: Dominus++ for the marvelous QOTW!
cheers,
Aldo
King of Laziness, Wizard of Impatience, Lord of Hubris
|
---|
In Section
Seekers of Perl Wisdom