in reply to Re^4: Counting occurence of a list of word in a file
in thread Counting occurence of a list of word in a file
It's an improvement !
If your File_Input/Testo.txt file contains more than one line, then I suggest
will produce a more complete result. (Perl will happily create an hash entry with (effectively) a zero value when required.)$arrayris{$key} += $count ;
You could also consider counting directly in your %arrayris:
while ($text =~ /\b$key\b/ig) { $arrayris{$key}++ ; } ;
Other things you might consider:
why you read the words into a hash (your %hash) when you only really use the keys... it may be preparatory to some future extension, I cannot tell.
similarly what is:
doing to justify its existence.my $value = $hash{$key};
recommend use strict ; and use warnings ; -- they will help you keep out of trouble !
the code is definitely "quick and dirty". If your either your wordlist or your input are very long, you may want to speed things up... But, the first rule of optimisation is: Don't do it (unless you really have to).
|
|---|