Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Difference between $1 and \1.

by LanX (Canon)
on Dec 27, 2012 at 11:38 UTC ( #1010501=note: print w/ replies, xml ) Need Help??


in reply to Difference between $1 and \1.

> Can anyone explain this behaviour ?

Google finds plenty of them by entering your title:

Perl Difference between $1 and \1

Now what are your problems left?

Within the matching part of regexes $1 can't be used for your purpose!

It's still bound to the match of the last regex:

DB<107> $_="a"; /(\w)/; $_='aaa'; /($1+)/; print $1 aaa

And regexes are older than Perl, \1 was the usual way to address first match, but variables with $-sigils belong to the syntax of scripting languages like Perl.

Cheers Rolf


Comment on Re: Difference between $1 and \1.
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (15)
As of 2015-07-02 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (41 votes), past polls