Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Count number of occurrences of a substr

by hbm (Hermit)
on Sep 28, 2011 at 18:45 UTC ( [id://928386]=note: print w/replies, xml ) Need Help??


in reply to Count number of occurrences of a substr

Here are two ways of counting matches:

$n++ while $str=~/this/g; $str =~ /this(?{$n++})(*F)/;

Replies are listed 'Best First'.
Re^2: Count number of occurrences of a substr
by ikegami (Patriarch) on Sep 28, 2011 at 18:53 UTC
    Note, $n needs to be a local our $n; instead of my $n; for the second snippet to work properly in a sub.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-23 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found