in reply to Is it right method to use Hash
which prints:my %test = ('a' => {'b' => 'c'}); while ( my($name1, $value1) = each %test ) { print "$name1:\n"; if(ref $value1 eq 'HASH') { while ( my($name2, $value2) = each %$value1 ) { print " $name2: $value2\n"; } } else { print "$value1\n"; } }
a: b: c
The test using ref might be a bit superfluous here, but it opens the door to indeed making the implementation using a recursive sub, and for using uneven leveled hashes. This way, you can nest to an indefinite level.
|
|---|