in reply to how to traverse thru this hash?

A bit more general approach to list all keys and strings in this complex structure:

my $VAR1 = { 'comp1' => { 'cmd2' => [ [ 'test2', 'type1', 'view1' ] ], 'cmd1' => [ [ 'test1', 'type1', 'view1' ], [ 'test2', 'type1', 'view1' ] ] } }; my $array = []; sub foo { my ($ref,$array) = @_; if (ref $ref eq 'ARRAY') { foreach my $ret (@{$ref}) { if (ref $ret ne '') { foo($ret,$array); } else { push @{$array},$ret; } } } elsif (ref $ref eq 'HASH') { foreach my $ret (keys %{$ref}) { if (ref $ref->{$ret} ne '') { push @{$array}, $ret; foo($ref->{$ret},$array); } else { push @{$array},$ref->{$ref}; } } } } foo($VAR1,$array); print " @{$array} \n";


I know the code is ugly, i tried to code fast and this ends up from it. Please point out mistakes politely, thank you.