# Build a database of the list heirarchy in the links file # Uses links.xml file for input. # table structure: # currentNodeID,ancestorNodeID,distance-from-ancestor @heirstack = (); $hs = 0; $ln = 0; $id = ""; while(<>){ ++$ln; while(/<\/?list/){ if(s/<\/list>//){ if($hs < 1){ die("Stack underflow at line $ln!\n"); } $id = pop(@heirstack); $hs--; if($hs < 1){ print "$id,,\n"; } else { for($i = 0; $i < $hs; $i++){ print "$id,$heirstack[$i],"; print $hs-$i; print "\n"; } } } elsif (s///){ #die($1); # Debug push(@heirstack, $1); $hs++; } else { die("Too stupid to handle list element at line $ln\n"); } } }