Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: How do I pass $1 to s///?

by Happy-the-monk (Abbot)
on Jan 06, 2006 at 16:54 UTC ( #521536=note: print w/ replies, xml ) Need Help??


in reply to How do I pass $1 to s///?

backreferences in perlre are used to be written \1, \2 ... tweetiepooh informs me that my perldoc used was outdated... and ikegami again corrects that.

Update: your programme prints "This is fish".
What did you expect it to print? "This is fish 1"?

Further update: see ikegami's solution below.

Third and then fourth update - in italics

Cheers, Sören


Comment on Re: How do I pass $1 to s///?
Replies are listed 'Best First'.
Re^2: How do I pass $1 to s///?
by ikegami (Pope) on Jan 06, 2006 at 17:42 UTC

    Still not quite right.

    Backreferences are \1, \2, etc in the LHS (regexp part) of the substitution.
    Backreferences are $1, $2, etc in the RHS (substitituion part) of the substitution.

    Lastest perlre (via [doc://perlre])

Re^2: How do I pass $1 to s///?
by tweetiepooh (Friar) on Jan 06, 2006 at 17:09 UTC
    \1,\2

    If warnings are on using these lead to
    \1 better written as $1

    There is a section in perlre about it.
Re^2: How do I pass $1 to s///?
by Anonymous Monk on Jan 06, 2006 at 17:03 UTC
    > your programme prints "This is fish".
    ...and gives a warning about $1 being uninitialised :(

    > What did you expect it to print? "This is fish 1"?
    Yeah. I've tried "fish \1", "fish \\1", "fish \\\1" as well though with no more luck!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2016-02-08 19:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?





    Results (283 votes), past polls