Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: memory variables (chp. 9 & 10 Learning Perl 3)

by mooseboy (Pilgrim)
on Sep 18, 2003 at 03:34 UTC ( #292308=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2021-06-13 17:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (57 votes). Check out past polls.

    Notices?