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

In reply to Re: Counting instances in a hash from an array by GrandFather
in thread Counting instances in a hash from an array by Gavin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.