in reply to Re: build mysql data structure from text file
in thread build mysql data structure from text file

Thank you!
Unfortunately, I accidentally misled you with my naming of the categories. They don't actually follow that comma separated format.
The key was "a category structure using leading tabs".
Still, ++ for providing me with an alternative way of looking at it.
  • Comment on Re: Re: build mysql data structure from text file

Replies are listed 'Best First'.
Re: Re: Re: build mysql data structure from text file
by Skeeve (Parson) on May 13, 2003 at 12:52 UTC
    Okay! Then my tabbed version of code ;-)
    print <<HEAD; ------------------------------------ | id | name | parent | ------------------------------------ HEAD $idcount=0; while (<DATA>) { # get rid of annoying tabs and \n chomp; s/^(\t*)//; # how many tabs? $tabs=length($1); # give it an id ++$idcount; # get the parent $parent=$parent[$tabs]+0; # set the parent $parent[$tabs+1]= $idcount; # print printf "| %2d | %-18s | %6d |\n", $idcount, $_, $parent; } print <<FOOT; ------------------------------------ FOOT __END__ cat1 cat1,sub1 cat1,sub1,sub-sub1 cat1,sub2 cat2 cat3 cat3,sub1