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

Re: counting overlapping patterns

by ikegami (Pope)
on Feb 18, 2005 at 21:49 UTC ( #432534=note: print w/replies, xml ) Need Help??


in reply to counting overlapping patterns

There's also the simple:

while ("AAAA" =~ /A(A+)/g) { $count += length($1); }

Unlike C's strlen, Perl's length doesn't loop, so this snippet is compliant with your request for no further looping.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2019-12-15 02:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?