Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Count multiple pattern matches

by Light Elf (Initiate)
on Dec 07, 2004 at 10:18 UTC ( #412875=note: print w/replies, xml ) Need Help??


in reply to Count multiple pattern matches

removing previous keywords from a string should make your algoritm faster.
... foreach my $k (@keywords){ my $matches_count = ( ($string =~ s/$k//ig ) ); ...

Replies are listed 'Best First'.
Re^2: Count multiple pattern matches
by calin (Deacon) on Dec 08, 2004 at 15:22 UTC

    This won't work correctly if keywords overlap.

    For example, consider the string foops. This actually matches both foo and oops. But if you remove foo in the first iteration, the remaining string (ps) won't match the keyword oops, thus reducing the match count for oops from 1 (the correct result) to 0.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2019-11-17 18:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (86 votes). Check out past polls.

    Notices?