Your attempt does sound overly complex, since I can't see a need for more than one hash, and (maybe) one array. I have no idea what you're doing with 4 hashes, and "reversing a hash" really doesn't make sense, since hashes aren't ordered.

Anyway, without seeing your attempt, the best I can do is say that my simplest solution would be to make a hash from the first file, with the numbers as keys and the number of times seen as values. Then I'd read lines from the second file, and print each number along with its value from the hash. That could introduce some inefficiency, since numbers from the first file that aren't in the second file (like 7 in your example) will still be put in the hash. choroba's solution avoids that by going through the second file first and creating an array to store the order, but that means extra storage for the array. Which is better would depend on how many values in the first file aren't found in the second file, but either way should work.

Aaron B.
Available for small or large Perl jobs; see my home node.


In reply to Re: frequency strings 2 files by aaron_baugher
in thread frequency strings 2 files by philbertcheese86

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.