Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Better way of doing!

by ramlight (Friar)
on Aug 12, 2013 at 13:27 UTC ( [id://1049121]=note: print w/replies, xml ) Need Help??


in reply to Re: Better way of doing!
in thread Better way of doing!

If this seems a little hard to follow for someone who is new to Perl, here is a version that works very similarly to kcott's code. However, even for those who find his code hard to follow (or maybe especially those who find it hard to follow), it is worth the trouble to understand the way the pattern is built and the way it is used with named captures.
use strict; use warnings; my @eachline = ( "transaction blah find blah blah think blah save_param", "start_sub blah url blah blah submit transaction blah find" ); my @keywords = qw{transaction find think save_param start_sub url subm +it}; my %count; for my $line (@eachline) { for my $pattern (@keywords) { $count{$pattern} += ($line =~ /$pattern/g); } } print "No. of matches for $_ is $count{$_}\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://1049121]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-25 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found