in reply to Counting instances in a hash from an array

Your sample code does not seem to relate to your question very much. You should provide some sample data, the output that is generated, and what you expected to be generated.

The following follows the sense of your description, not of your code:

use strict; use warnings; my @midWords = qw(stop start finish); my %sentences = ( 1 => "Start starts the start sentence.", 2 => "This is a sentence in the middle.", 3 => "This is not the start or the finish, nor even a good place t +o stop.", 4 => "This is the finish and a good place to stop." ); my %testWords; @testWords{@midWords} = (0); foreach my $sentence (values %sentences){ for (split /\W/, $sentence) { ++$testWords{lc $_} if exists $testWords{lc $_}; } } print join "\n", map {"$_ => $testWords{$_}"} sort keys %testWords;

Prints:

finish => 2 start => 3 stop => 2

Read I know what I mean. Why don't you? for some tips on posting this sort of question.


DWIM is Perl's answer to Gödel