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 (Abbot)
on Mar 29, 2013 at 16:51 UTC ( [id://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}; }

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1026172]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found