Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Count multiple pattern matches

by Zaxo (Archbishop)
on Dec 07, 2004 at 02:04 UTC ( #412806=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use strict;
    my (@keywords, %keyword)=qw/foo bar 12345 abcd/;
    my ($string, %result) = "foobarfoo1234523423412345abcdefsadfabc";
    
  2. or download this
    @keyword{@keywords} =  map {qr/\Q$_\E/} @keywords;
  3. or download this
    $result{$_} = () = $string =~ $keyword{$_}
        for (keys %keyword);
    
  4. or download this
    my @regexen = map {
        qr/(?:\Q$_\E(?{$result{$_}++}))/
    } @keywords;
    ...
        local $" = '|';
        qr/@regexen/;
    };
    
  5. or download this
    $string =~ /$re/g;
    print "$_: $result{$_}\n" for @keywords;
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2019-11-15 23:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (85 votes). Check out past polls.

    Notices?