Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: m//g behaves strange...

by converter (Priest)
on Nov 09, 2003 at 21:54 UTC ( #305723=note: print w/replies, xml ) Need Help??


in reply to m//g behaves strange...

In scalar context m//g doesn't return size of the list it would give back when called in list context,

If you want the number of elements in the list returned by a pattern with the /g modifier when evaluated in list context, you can use a list assignment in scalar context, which produces the number of its elements. In this case, we assign to an empty list:

$_ = "456"; $count = () = /./g; print $count; # prints 3

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://305723]
help
Chatterbox?
[Corion]: There are worse ways to enter a website ;)
[Lady_Aleena]: Corion, I'm just hoping Cookies doesn't get too annoying.
[Corion]: Naah, if people got annoyed, they'd tell you ;)

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2017-04-26 08:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (471 votes). Check out past polls.