in reply to Re: How to find all occurrences of a key in a deeply nested structure?
in thread How to find all occurrences of a key in a deeply nested structure?

Very helpful. I was on my way of doing the same thing, but didn't see the needed container. If I were to try and get a unique list of all the values, does this make sense:
my $struct = {...}; # the hash of hashes in the question my $found; Data::Walk::walk \&wanted, $struct; print join(" ",sort keys %$found) ,"\n"; sub wanted{ if (/^values$/){ foreach ( keys %{$Data::Walk::container->{$_}} ){ $found->{$_}=1; } } }



Demize
  • Comment on Re^2: How to find all occurrences of a key in a deeply nested structure?
  • Download Code

Replies are listed 'Best First'.
Re^3: How to find all occurrences of a key in a deeply nested structure?
by Anonymous Monk on Oct 20, 2011 at 15:40 UTC
    No, don't do that, do it the way I did it :) except only push if not $Data::Walk::seen
      But that would return duplicates and not a unique set, which is why I was storing in a hash, to do the cleanup for me :)
        Ok, like this
        print join ' ', UniqueWalkers( $struct ); sub UniqueWalkers { my %found; Data::Walk::walk( sub { if (/^values$/) { foreach ( keys %{ $Data::Walk::container->{$_} } ) { $found{$_}++; } } return; }, @_ ); return sort keys %found; }