in reply to frequency strings 2 files
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.
|
|---|