Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: How can I access the number of repititions in a regex?

by amarquis (Curate)
on Mar 11, 2008 at 18:42 UTC ( [id://673582]=note: print w/replies, xml ) Need Help??


in reply to Re: How can I access the number of repititions in a regex?
in thread How can I access the number of repititions in a regex?

Would you mind explaining how this works? I understand that the empty () imposes list context on the right, making the match return the number of matches.

Then you are left with the assignment of a scalar to an empty list, which is in turn assigned to $count. I guess I'm just not sure how the "5" propagates over the empty list in the middle to land in the $count variable.

Sorry if I'm being dense.

Replies are listed 'Best First'.
Re^3: How can I access the number of repititions in a regex?
by Errto (Vicar) on Mar 11, 2008 at 20:36 UTC
    I understand that the empty () imposes list context on the right...
    correct
    ...making the match return the number of matches.
    Not quite. The match returns a list of matches. A list assignment in scalar context returns the number of elements in the list, regardless of the number of those elements that actually get assigned to anything (in this case, zero). So the "5" doesn't propagate. It's the use of the assignment in scalar context that creates the "5".
      Ah, thank you. Sorry, I don't know why I was confusing the two, it doesn't even make sense the way I was thinking about it.
Re^3: How can I access the number of repititions in a regex?
by GrandFather (Saint) on Mar 12, 2008 at 02:14 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-03-28 21:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found