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

Re: Help to improve script that searches a file for key words in a second file.

by jwkrahn (Monsignor)
on Mar 29, 2013 at 16:51 UTC ( #1026172=note: print w/ replies, xml ) Need Help??


in reply to Help to improve script that searches a file for key words in a second file.

if($annotation =~ /(\b($term)\b|$term-)\b|(-$term)\b/i) { $nTermHits {$term}++; $nTotalHits++; push(@annotationlist, "$annotation\n"); }

You are not using the contents of the capturing parentheses so you could simply write that as:

if($annotation =~ /(?:\b$term|$term-|-$term)\b/i) {


foreach $term (@terms) { if ($nTermHits {$term} > 0) { printf "%s\t%d\n", $term, $nTermHits {$term}; } }

That would be better as:

foreach $term (keys %nTermHits) { printf "%s\t%d\n", $term, $nTermHits {$term}; }


Comment on Re: Help to improve script that searches a file for key words in a second file.
Select or Download Code
Re^2: Help to improve script that searches a file for key words in a second file.
by mastarr (Novice) on Apr 01, 2013 at 18:31 UTC

    Thanks. That was exactly what I was looking for.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1026172]
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 2014-09-20 10:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (158 votes), past polls