Copy and paste is your friend. Neither the sample data nor the sample code compile. When the obvious errors are fixed the code only generates the first line of output you show. If the exit is taken out the output still isn't anything like the sample output you give. Even then, the output you show is not consistent with the description you gave in the original node. I notice some duplication in your sample hash - is that intentional?

Show us a self contained script that runs and we may be able to reproduce your results. Anyway, here is my version of something that may relate to what you want:

#!/usr/bin/perl use strict; use warnings; my %dtree = ( L1 => { L2b => {L2b1 => {}, L2b2 => {}}, L2a => {L3b => {L4a => {}}, L3a => {}} }, L3b => {L4a => {}}, L2b => {L2b1 => {}, L2b2 => {}}, L2a => {L3b => {L4a => {}}, L3a => {}} ); processDtree(\%dtree); sub processDtree { my ($rh_dtree, @nodes) = @_; print join ('.', map {"nested-$_"} @nodes), "\n" if @nodes; processDtree ($rh_dtree->{$_}, @nodes, $_) for sort keys %$rh_dtre +e; }

Prints:

nested-L1 nested-L1.nested-L2a nested-L1.nested-L2a.nested-L3a nested-L1.nested-L2a.nested-L3b nested-L1.nested-L2a.nested-L3b.nested-L4a nested-L1.nested-L2b nested-L1.nested-L2b.nested-L2b1 nested-L1.nested-L2b.nested-L2b2 nested-L2a nested-L2a.nested-L3a nested-L2a.nested-L3b nested-L2a.nested-L3b.nested-L4a nested-L2b nested-L2b.nested-L2b1 nested-L2b.nested-L2b2 nested-L3b nested-L3b.nested-L4a
True laziness is hard work

In reply to Re^3: walking a hash by GrandFather
in thread walking a hash by rjl

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.