Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: How to find all occurrences of a key in a deeply nested structure?

by deMize (Monk)
on Oct 20, 2011 at 15:35 UTC ( [id://932710]=note: print w/replies, xml ) Need Help??


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; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://932710]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-24 08:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found