you're right it does sound's like homework but is has passed quite some time since i last attended any real classes. so what i tried so far is through recursion catch the pattern to transform it to the nice tree :
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;
}
there are some relict's in the code but that is because i'm still trying to figure it out.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.