in reply to Need advice on checking two hashes values and keys
Given the nature of the data (and depending how it is supposed to be used later), I would probably use an array of hashes (AoH), something like this:
which yields a structure like this:my @numbers = ( undef, { it => "uno", sp => "uno", fr => "un"}, { it => "due", sp => "dos", fr => "deux"}, { it => "tre", sp => "tres", fr => "trois"}, # ... );
The advantage is that the array stays in order. Note that I created the first array element as undef, in order to have a natural correspondence between the element index and the numbers in he various languages (alternatively, I could have put a line for zero in all three languages). Each element of the array is a reference to a hash containing the number names in the various language.0 ARRAY(0x6004f9c80) 0 undef 1 HASH(0x600636430) 'fr' => 'un' 'it' => 'uno' 'sp' => 'uno' 2 HASH(0x6005d18a8) 'fr' => 'deux' 'it' => 'due' 'sp' => 'dos' 3 HASH(0x6005d1920) 'fr' => 'trois' 'it' => 'tre' 'sp' => 'tres'
To access to the Italian name of 2, simply try:
which should happily print "due".print $numbers[2]{it};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need advice on checking two hashes values and keys
by Anonymous Monk on Jun 04, 2015 at 22:54 UTC | |
by perlynewby (Scribe) on Jun 04, 2015 at 23:32 UTC |