Are you really counting words with a shell command? Check this out:

my $string="It is a guide to action which ensures that the military al +ways obey the commands of the party"; my %counts; foreach (split(' ',$string)) { $counts{$_}++; } foreach (keys %counts) { print "Word '$_' occurs $counts{$_} times\n"; }

will print

Word 'the' occurs 3 times Word 'It' occurs 1 times Word 'a' occurs 1 times Word 'of' occurs 1 times Word 'ensures' occurs 1 times Word 'which' occurs 1 times Word 'commands' occurs 1 times Word 'that' occurs 1 times Word 'is' occurs 1 times Word 'to' occurs 1 times Word 'always' occurs 1 times Word 'military' occurs 1 times Word 'guide' occurs 1 times Word 'party' occurs 1 times Word 'action' occurs 1 times Word 'obey' occurs 1 times

Oh, and the problem you were asking about: Just use foreach (key ...) on one hash and compare with the second hash. Then do the same with the second hash but only look at keys not in the first hash (as they are the only ones not handled by the first foreach loop).


In reply to Re: Comparison between keys in hash by jethro
in thread Comparison between keys in hash by sarvan

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.