in reply to Re: representing a tree
in thread representing a tree
there are some relict's in the code but that is because i'm still trying to figure it out.use strict; open (T, "<", "file.txt")|| die "$!"; open (OUT, ">", "out.txt") || die "$!"; my $t = $ARGV[0];# $t could be 3 not 1 so that i can start from that p +oint my %hash; while (<T>){ m/^(\d+?),(\d+?)\n/g; my ($child, $parent) = ($2,$1); push @{$hash{$child}},$parent; } walk($t); sub walk { my $numb = shift; print OUT "\|->$numb\n"; #my @walk = $numb; for (@{$hash{$numb}}){ #push @walk, #print OUTNOD "\|->>>"; walk($_); print OUTNOD "\|->>"; } #return @walk; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: representing a tree
by moritz (Cardinal) on Jul 03, 2008 at 10:28 UTC |