in reply to build mysql data structure from text file
print <<HEAD; ------------------------------------ | id | name | parent | ------------------------------------ HEAD $idcount=0; while (<DATA>) { # get rid of annoying tabs and \n chomp; s/^\s*//; # name this entry $thisentry= $_; # give it an id $id{$thisentry}= ++$idcount; # remove last sub-category s/,?[^,]+$//; # set the parent $parent{$thisentry}=$id{$_}+0; # print printf "| %2d | %-18s | %6d |\n", $id{$thisentry}, $thisentry, $parent{$thisentry}; } print <<FOOT; ------------------------------------ FOOT __END__ cat1 cat1,sub1 cat1,sub1,sub-sub1 cat1,sub2 cat2 cat3 cat3,sub1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: build mysql data structure from text file
by fireartist (Chaplain) on May 13, 2003 at 12:38 UTC | |
by Skeeve (Parson) on May 13, 2003 at 12:52 UTC |