Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Count multiple pattern matches

by Mr. Muskrat (Canon)
on Dec 07, 2004 at 02:39 UTC ( #412814=note: print w/replies, xml ) Need Help??


in reply to Count multiple pattern matches

It's probably not the best way to do it but this is what sprang to mind when I saw this post. It's also very similar to what you already have.

use strict; my @keywords = qw/foo bar 12345 abcd/; my $string = "foobarfoo1234523423412345abcdefsadfabc"; my $re = join('|',@keywords); my %result; $result{$1}++ while ($string =~ /($re)/ig); foreach my $s (keys %result){ print "$s=>$result{$s}\n"; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2019-12-10 01:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?