in reply to Need advice on checking two hashes values and keys
Your first loop is fine; it reads lines from the first file and puts them in a hash as keys and values. Your second loop is kind of a mess. You have a few choices:
This would mean changing your first loop so that it stores keys and values as $hash{$key}[0] and those from the second loop as $hash{$key}[1].$hash = ( uno => [ 'uno','un' ], due => [ 'dos','due' ], tre => [ 'tres','tris' ], # and so on );
A problem with solutions #2 and #3 is that a hash is not ordered, so when you loop through the hash to print out the lines, they will not be in the order you want. To fix that, you would have to use an array of arrays instead of a hash, or keep a separate array of the keys to hold their order, or use a module that provides an ordered hash. If you use solution #1, you'll be printing them out in the same order you find them in the second file, which appears to be what you want.
Aaron B.
Available for small or large Perl jobs and *nix system administration; see my home node.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need advice on checking two hashes values and keys
by perlynewby (Scribe) on Jun 03, 2015 at 22:54 UTC | |
by aaron_baugher (Curate) on Jun 03, 2015 at 23:29 UTC | |
|
Re^2: Need advice on checking two hashes values and keys
by perlynewby (Scribe) on Jun 04, 2015 at 20:53 UTC | |
by aaron_baugher (Curate) on Jun 04, 2015 at 21:54 UTC | |
by perlynewby (Scribe) on Jun 04, 2015 at 23:23 UTC | |
by aaron_baugher (Curate) on Jun 05, 2015 at 02:01 UTC | |
by Anonymous Monk on Jun 09, 2015 at 18:41 UTC | |
|