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

(zdog) Re: how to get the number of times a pattern matched

by zdog (Priest)
on Jun 02, 2001 at 00:43 UTC ( #85070=note: print w/replies, xml ) Need Help??

in reply to how to get the number of times a pattern matched

The pattern matching function m// should return the number of times the pattern matched.

Update: Wups. My mistake. Nevermind.

Update 2: However, s/// does what I thought m// does, so you can do something like:

my $count = ($string =~ s/(pattern)/$1/g;)

Good luck.

Zenon Zabinski | zdog |

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://85070]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2017-06-23 02:37 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (533 votes). Check out past polls.