in reply to Need advice on checking two hashes values and keys

TIMTOWTDI, There is more than one way to do it.

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:

my @numbers = ( undef, { it => "uno", sp => "uno", fr => "un"}, { it => "due", sp => "dos", fr => "deux"}, { it => "tre", sp => "tres", fr => "trois"}, # ... );
which yields a structure like this:
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'
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.

To access to the Italian name of 2, simply try:

print $numbers[2]{it};
which should happily print "due".

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

    Hey, someone said TIMTOWTDI. hehehe

    #!/usr/bin/perl # http://perlmonks.org/?node_id=1129003 use warnings; use strict; $_ = <<END; uno = uno due = dos tre = tres quattro = quatro cinque = cinco sei = seis sette = siete otto = ocho nouve = nueve dieci =diez uno = un due = due tre = tris quattro = quatre cinque = cinq sei = six sette = sept dieci = dix END print "$1 => $2, $3\n" while /^(\w+) = *(\w+)\b(?=.*\n\n.*^\1 = (\w+)) +/gms;

      OH MIO DIO! this is a cool way to do it.

      I need to learn ALL KIND of types hashes, hashrefs, hash table,..., for now since I get confused on them but using regex looks cool and will try this method too. pretty cool.