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

Replies are listed 'Best First'.
Re^2: How do I pass $1 to s///?
by ikegami (Patriarch) 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 (Hermit) 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!