Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Count multiple pattern matches

by Zaxo (Archbishop)
on Dec 07, 2004 at 02:04 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://412806]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-19 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found