in reply to Re^6: Perl modules or standard tools for searching hierachical data
in thread Perl modules or standard tools for searching hierachical data

Hello,
I forgot to post the code I am using
#!/usr/bin/perl use strict; use warnings; my %node; my $folder = "P:\\Prod-Operations\\Maint-Eng\\Maintenance Projects\\IN +F\\DB\\IFDB\\TAGHIERARCHY\\PerlScripts"; my $resultfile = "resultset.txt"; my $interset01 = "interset01.txt"; my $interset02 = "interset02.txt"; open (DATA, "< $folder\\$resultfile") || die "could not open file: $!" +; while (<DATA>) { my ( $c, $p ) = split /\|/; if ( $c eq $p ) { # these are easy, so finish them first print; next; } if ( exists( $node{$c}{child_of} )) { warn "$.: bad record: $c is child of both $p and $node{$c}{chi +ld_of}\n"; next; } $node{$c}{child_of} = $p; $node{$p}{parent_of}{$c} = undef; } # begin the sorted output by looping over values that do not have pare +nts: # open (INT01,">$folder\\$interset01") or die "Can not open file $fold +er\\$interset01 for writing, quitting\n"; for my $parent ( grep {!exists( $node{$_}{child_of} ) } keys %node ) { my $children = $node{$parent}{parent_of}; # ref to hash of child +values trace_down( $children, \%node ); } sub trace_down { my ( $kids, $tree ) = @_; for my $kid ( keys %$kids ) { # print INT01 "$kid|$$tree{$kid}{child_of}"; print "$kid|$$tree{$kid}{child_of}\n"; if ( exists( $$tree{$kid}{parent_of} )) { trace_down( $$tree{$kid}{parent_of}, $tree ); } } }
  • Comment on Re^7: Perl modules or standard tools for searching hierachical data
  • Download Code