Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: $1 in variable regex replacement string

by dada (Chaplain)
on Feb 13, 2003 at 10:03 UTC ( #234936=note: print w/replies, xml ) Need Help??


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.

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"
you can find the original question along with MJD's solution and discussion here.

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

  • Comment on Re: $1 in variable regex replacement string

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://234936]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2022-05-25 02:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (84 votes). Check out past polls.

    Notices?