Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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]: Once upon a time I had automatic tests for checking the synopsis, but I stopped doing that because the setup was too fragile on CPAN testers for extracting code from the SYNOPSIS.
[Corion]: Maybe I should move the extraction of the code from the SYNOPSIS section into the author tests, or something like that...
[choroba]: Corion Sounds reasonable
[Corion]: choroba: Yeah - I basically have the same for regenerating README and README.mkdown already, except that I do that in Makefile.PL, but I guess one or the other thing should somehow work ;)
[ambrus]: was this bug: https://rt.cpan. org/Public/Bug/ Display.html?id= 59814
[Corion]: ambrus: Oh - that one would be much harder to automate... The SYNOPSIS section should mostly be a runnable program IMO, but I write only small snippets in my documentation for single functions/methods, and creating the appropriate environment for ...
[Corion]: ... those in an automated fashion seems somewhat hard to me. Although it should do wonders for the test coverage ;)

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2017-02-27 12:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (383 votes). Check out past polls.