in reply to Re: Problem in counting the occurrences of a string in a text file
in thread Problem in counting the occurrences of a string in a text file

Thanks for the comment.
But if I try using your code, I get the same result as mine. Every couple has the same number of occurrences, and that just isn't possible. I'm sorry if I cannot make it more clear, is just I don't know how to explain that.
  • Comment on Re^2: Problem in counting the occurrences of a string in a text file

Replies are listed 'Best First'.
Re^3: Problem in counting the occurrences of a string in a text file
by linuxer (Curate) on Dec 29, 2008 at 21:31 UTC

    I think your problem is, that you only have one counter variable, which is increased for each individual matching.

    Consider something like this:

    #my $conto = 0; #### REMOVED; not needed my %arrayris; while (my $text = <LISTAPAROLE>){ for my $key (keys %hash){ my $value = $hash{$key}; if ($text =~/$key\/$key\/.*con\/con\/E.*$value\/$value\/S/is){ ### increase for each key/value pair individually $arrayris{ join '-', $key, $value }++; } } } while ( my ($k,$v) = each %arrayris ) { print CONTEGGIO "($k) => $v\n"; }