Why is use strict; commented out!? As previously mentioned, this is hiding serious errors. Specifically, you are trying to store both "1" and a hash reference at $h{b}{1}. One simple fix is to use undef instead of 1.

use strict; use warnings; use Data::Dumper; my %h; $h{'B'}{1}=undef; for my $a ('A'..'C'){ for my $b (0..2){ for my $c ('a'..'c') { $h{$a}{$b}{$c}=undef; } } } print "Data Dumper-------------------\n"; print Dumper (\%h); print "Loop----------------\n"; foreach my $top (sort keys %h) { print $top =~ /^\s*$/ ? "<blank>" : $top, "\n"; next if !ref($h{$top}); foreach my $second (sort keys %{$h{$top}}) { print "...", $second =~ /^\s*$/ ? "<blank>" : $second, "\n"; next if !ref($h{$top}{$second}); foreach my $third (sort keys %{$h{$top}{$second}}) { print "......", $third =~ /^\s*$/ ? "<blank>" : $third, "\ +n"; next if !ref($h{$top}{$second}{$third}); } } } print "Print_tree------------------\n"; print_tree(\%h); sub print_tree { my ($tree, $depth) = @_; $depth ||= 0; if ($depth > 5) { warn "max depth reached\n"; return; } my $indent = '...' x $depth; for (sort keys %$tree) { print($indent, /^\s*\z/ ? "<blank>" : $_, "\n"); print_tree($tree->{$_}, $depth+1) if ref($tree->{$_}); } }

In reply to Re^5: Printing a tree-view of a hash of hashes by ikegami
in thread Printing a tree-view of a hash of hashes by pdxperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.