There's more than one way to do things | |
PerlMonks |
Re^3: Need advice on checking two hashes values and keysby aaron_baugher (Curate) |
on Jun 04, 2015 at 21:54 UTC ( [id://1129121]=note: print w/replies, xml ) | Need Help?? |
(I'd suggest that you keep posting to this thread as long as you're working on the same problem, unless people stop responding to it.) Ok, let's say you want to create a hash of two-element arrays, with the hash keys being the Italian numbers, each one pointing to a reference to a two-element array holding the Spanish and French numbers, in that order. Then as you're going through the first loop (Italian = Spanish), you need to insert the Spanish numbers as the first element of an array rather than a simple value: $hash{$italian} = [ $spanish ];The square brackets return a reference to an array, which is a scalar that can be stored as a value in the hash. So now it looks like this, with references to one-element arrays as the values:
Then in the second loop, you need to add the French numbers to the arrays corresponding to their matching Italian hash keys. There are two ways you could do this:
Then when you're ready to print them out, you loop through the keys of the hash, printing the key and the elements of the sub-array as you wish:
The trick is keeping track of what level of the structure you're dealing with, and getting the sigils (and arrows, if necessary) right for pointing to the right things, whether values or references. Aaron B.
In Section
Seekers of Perl Wisdom
|
|