Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Getting the number of times a regexp matches

by dchetlin (Friar)
on Dec 07, 2000 at 18:33 UTC ( #45500=note: print w/ replies, xml ) Need Help??


in reply to Getting the number of times a regexp matches

No one mentioned the canonical and most Perlish way to do this:

my $count = () = $str =~ m/pattern/g;

I suspect it offers little benefit in terms of efficiency, and can be confusing contextually. I do feel that it's the most succinct and elegant, however.

Update: My apologies; while I was writing this and getting distracted, it was mentioned ahead of me, and an interesting discussion of it followed. Ah well.

-dlc


Comment on Re: Getting the number of times a regexp matches
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2015-07-29 17:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (266 votes), past polls