Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Perl is psychic?!

by KM (Priest)
on Mar 06, 2001 at 05:13 UTC ( #62403=note: print w/ replies, xml ) Need Help??


in reply to Perl is psychic?!

Yes, Perl is psychic... but not in this case. If you look at perlvar you will see:

 $&      The string matched by the last successful pattern
               match (not counting any matches hidden within a
               BLOCK or eval() enclosed by the current BLOCK).
               (Mnemonic: like & in some editors.)  This variable
               is read-only and dynamically scoped to the current
               BLOCK.

So, since .* matched 'foo', $& is set when you use it. If you make your pattern /\d.*/ you will find you will get no output in your same test case.

(root@frodo):/tmp>
# cat t.pl
'foo' =~ m/\d.*/;
print eval <STDIN>;
(root@frodo):/tmp>
# perl t.pl
$&
(root@frodo):/tmp>
#

Cheers,
KM


Comment on Re: Perl is psychic?!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (15)
As of 2015-07-06 18:22 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 (80 votes), past polls