in reply to memory variables (chp. 9 & 10 Learning Perl 3)

As others have said, \1, \2 etc are used inside the pattern, and $1, $2 outside it. But I'm pretty sure of two things: a) you're missing a closing paren in the examples and b) you've reproduced what I assume is a typo in the book (p111 in my copy), where it says 'flintsone' instead of 'flintstone' (no doubt merlyn will correct me if I'm wrong in my assumption ;-). So I presume it should really be:

/((fred|wilma) (flintstone)) \2/ # could be fred flintstone fred /((fred|wilma) (flintstone)) \1/ # could be fred flintstone fred flint +stone

HTH, mooseboy

Replies are listed 'Best First'.
Re: Re: memory variables (chp. 9 & 10 Learning Perl 3)
by xtype (Deacon) on Sep 18, 2003 at 17:02 UTC
    Assuming that mooseboy is correct, and it is simply that you left out a ")"...
    I do not have a copy of this book on hand, so I do not know the surrounding text, however, this might help to clear things up a bit:
    /((fred|wilma) (flintstone)) \2/ # could be fred flintstone fred /((fred|wilma) (flintstone)) \1/ # could be fred flintstone fred flint +stone /((fred|wilma) (flintstone)) \3/ # could be fred flintstone flintstone
    \1 being what is contained in the first paren encountered (until its' closing paren -which you left out-), in this case will always contain both \2 and \3.
    ((\2)\1(\3))

    cheers, -xtype