in reply to Re: how to construct tree from parent pointer list
in thread how to construct tree from parent pointer list
I am in search of wisdom!
I was wondering if you could explain a couple things for me from your example:
$nodes{$_}{name}||=$_ for $c,$p;
-- I'm not use to putting '$_' as a key for a hash. I am also not sure what '||=$_' means/does. Can you explain?
I'm also not sure why you are deleting children...
delete $nodes{$_} for @children;
Sorry for the newbie questions -- I've been dabbling in Perl for years, and I use hashes a lot but my syntax is still on the simple side.
I have another question. Any tips on printing nested hashes? I use Data::Dumper all the time, but I usually just use the default output. What I am looking for is the "full path". For example, in the above example, we have this:
'name' => 'a', 'kids' => { 'c' => { 'name' => 'c', 'kids' => { 'e' => { 'name' => 'e' }, 'f' => { 'name' => 'f'
-- I'd like to print out something like this:
a a:c a:c:e a:c:f
I usually just print each piece of the hash, which isn't too hard if I created the hash. For example, if I had a hash ref that had name/address information, I'd do something like:
print $hash->{$key}->{'name'} . "\t"; print $hash->{$key}->{'addres'} . "\n";
But if the hash is created via autovivification (for example, let's say I am constructing a complex node tree from a parent-child list of several thousand nodes) I get stumped on how I'd be able to print the full path of each element in the hash.
Does that make any sense? I am waking up and keeping two little kids from killing each other. ;)
Any tips much appreciated!!
Thanks.
--Bryan
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: various hash construction/ printing questions..
by demerphq (Chancellor) on Jun 13, 2009 at 16:42 UTC | |
by bryank (Acolyte) on Jun 13, 2009 at 22:50 UTC | |
by demerphq (Chancellor) on Jun 14, 2009 at 10:12 UTC | |
by bryank (Acolyte) on Jun 17, 2009 at 00:51 UTC | |
by bryank (Acolyte) on Jun 30, 2009 at 16:28 UTC |