Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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
Replies are listed 'Best First'.
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 chilling in the Monastery: (19)
As of 2015-07-29 16:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (265 votes), past polls