uuse strict; use warnings; sub PrintHash{ my ($href, $indent_text, $level) = @_; $level ||= 0; while (my ($k, $v) = each(%$href)) { print +("\t" x $level), "${indent_text}$k = "; if (not ref $v){ #SCALAR print "$v\n"; }elsif (ref $v eq "HASH"){ print "\{\n"; PrintHash($v,"",$level+1); print +("\t" x $level),"}\n"; }elsif (ref $v eq "ARRAY"){ local $,=", "; print "\@(@$v)\n"; # Could do a better job by writing sub PrintArrayRef{} }else{ die "ERROR: Invalid type:",ref($v),"\n"; } } } PrintHash({Uno=>1, Dos=>2, Tres=>3, Cuatro=>[1,2,3,4], Cinco=>{otro=>99,rojo=>'Red'}}, "Error codes:", 0); #### > perl .\printhash.pl Error codes:Cuatro = @(1 2 3 4) Error codes:Uno = 1 Error codes:Dos = 2 Error codes:Tres = 3 Error codes:Cinco = { otro = 99 rojo = Red }