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
|