in reply to Logic for sorting of this given array
Which, as you can see, lends itself to a nice recursive subroutine to dump the given tree.my %tree = ( "Office of President" => { Recruiting => undef, 'Pipe line' => undef, Software => { MIS => undef, 'System Operations' => undef, }, } ); print dump_tree(\%tree); sub dump_tree { my($tree, $indent) = ( $_[0], $_[1] || 0 ); my $ret = ''; for(sort keys %$tree) { $ret .= " " x $indent."$_\n"; $ret .= dump_tree($tree->{$_}, $indent + 2) if ref $tree->{$_} and ref $tree->{$_} eq 'HASH'; } return $ret; } __output__ Office of President Pipe line Recruiting Software MIS System Operations
_________
broquaint
update: changed code to better reflect the desired data structure
|
|---|