#!/usr/bin/perl -w # use strict; use warnings; use Data::Dumper; my %singleLevelHash = (); my %multiLevelHash = ( 'firstSampleKey' => 'SampleValue', 'secondSampleKey' => { 'secondLevelSampleKey' => { 'thirdLevelSampleKeyOne' => 'thirdLevelSampleValue', 'thirdLevelSampleKeyTwo' => 'thirdLevelSampleValue', 'thirdLevelSampleKeyThree' => 'thirdLevelSampleValue', } } ); # print Dumper \%multiLevelHash; show_this(\%multiLevelHash); # foreach my $firstSampleKey ( sort keys %multiLevelHash ) { # print $firstSampleKey . "\n"; # foreach my $secondLevelSampleKey ( sort keys $multiLevelHash{$firstSampleKey} ) { # print $secondLevelSampleKey . "\n"; # } # } sub show_this { my ($x) = @_; if (ref $x eq "") { printf " Value: '%s'\n", $x; } elsif (ref $x eq 'SCALAR') { printf " SCALAR ref: '%s'\n", $$x; } elsif (ref $x eq 'HASH') { print " HASH ref '$x':\n"; foreach my $key (keys %$x) { my $val = $x->{$key}; print " $key: "; show_this($val); } } elsif (ref $x eq 'ARRAY') { print " ARRAY re '$x':\n"; foreach my $val (@$x) { show_this($val); } } }