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
In reply to Re^3: walking a hash
by GrandFather
in thread walking a hash
by rjl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |