Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: The value of pattern match variable $&

by cdarke (Prior)
on May 15, 2006 at 09:04 UTC ( #549406=note: print w/replies, xml ) Need Help??


in reply to The value of pattern match variable $&

perlvar defines $& ($MATCH) with the cavet "not counting any matches hidden within a BLOCK", and yours are, although I admit surprise at the behaviour.
  • Comment on Re: The value of pattern match variable $&

Replies are listed 'Best First'.
Re^2: The value of pattern match variable $&
by bart (Canon) on May 15, 2006 at 09:57 UTC
    It's by design. There's an implicit local for match variables in blocks.

    And re "reliability": a regexp that doesn't match will not affect the match variables, they will not (necessarily) be undef, but the value they got on the last succesful regexp — with the above caveat.

      That doens't quite explain it. It the first loop, it's as if the implicit local $& is outside of the loop — It prints 'bar' on the 'baz' pass of the loop — while in the second loop, it's as is the implicit local $& is inside of the loop.

      Could
      print "$&\n" unless /bar/;
      suffer from a problem similar to the one from which
      my ... if ...;
      suffers?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2022-05-20 18:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (75 votes). Check out past polls.

    Notices?