Code :
#!usr/bin/perl use strict; use warnings; #Lexical variable for filehandle is preferred, and always error check opens. open my $keywords, '<:utf8', 'keywords.txt' or die "Can't open keywords: $!"; open my $search_file, '<:utf8', 'search.txt' or die "Can't open search file: $!"; open my($file), '<', 'search.txt'; my %words; # hachage de compteurs while (my $word = <$keywords> ) { $word=~ s/^\ s+|\ s+$//; # changé, parce que tu as plus d'un blanc a la suite de tes mots next if $word =~ /^$/; $words{$word} = 1; } my %freq; while( my $line = <$file> ) { foreach my $word (split(' ', $line)) { $freq{$word}++ if $words{$word}; ; } } print "$word $freq{$word}\n"; }
|