Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: various hash construction/ printing questions..

by bryank (Acolyte)
on Jun 30, 2009 at 16:28 UTC ( #776093=note: print w/replies, xml ) Need Help??


in reply to Re: various hash construction/ printing questions..
in thread how to construct tree from parent pointer list

Hi. I am having problems incorporating your output subroutine. Can you help?

use Data::Dumper; use strict; use warnings; my %nodes; my @children; while (<>) { chomp; my ($c,$p)=split "\t"; push @children,$c unless $nodes{$c}; $nodes{$_}{name}||=$_ for $c,$p; $nodes{$p}{kids}{$c}=$nodes{$c}; } delete $nodes{$_} for @children; my @roots=keys %nodes; #print Dumper($nodes{$_}) for @roots; print_inorder(%nodes); sub print_inorder { my $node= shift; print $node->{name}, "\n"; print_inorder($_) for sort { $a->{name} cmp $b->{name} } values %{ $node->{kids} || {} }; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2020-11-26 04:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?