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

Re: How to count substrings in an array?

by mbethke (Hermit)
on Feb 03, 2013 at 07:11 UTC ( #1016784=note: print w/replies, xml ) Need Help??


in reply to How to count substrings in an array?

Edit: forum glitch? As is evident from the title this should have ended up here

The "goatse operator" can make this a bit shorter and faster: $count =()= $string =~ /RE/; counts the number of matches in $string, so

my $count; for(@array) { $count +=()= /RE/g; }
does what you want. It evaluates the regex in list context so it returns the list of matches and then forces it to scalar context without assigning the list anywhere.

Replies are listed 'Best First'.
Re^2: How to count substrings in an array?
by CKL on Feb 03, 2013 at 07:21 UTC
    sorry, I figured it out and meant to delete it, rather than leave a blank. thank you for your time anyway.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1016784]
help
Chatterbox?
[Your Mother]: Take my advice with a grain of salt. I haven't done a new CPAN release in years at this point.
[LanX]: I want to author a new module for CPAN w/o complicated build structure
[LanX]: ther is also Dist::Zilla :-/
[LanX]: How to make a CPAN Module Distribution from 2002
[Your Mother]: Dist::Zilla is kind of the nuclear option. I set it up back in the day but it's really targeted at authors who are managing MANY modules and want to automate everything.
[erix]: perlancar should know ;)
[LanX]: see warning
[Your Mother]: Thanks for the warning notice.
[LanX]: :p

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2017-08-18 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (306 votes). Check out past polls.

    Notices?