I used DBD::CSV to make a small table containing IDs, category names and parent categories. Hopefully you can adapt this to your needs.
Codecategories#! /usr/bin/perl use strict ; use warnings ; $|++ ; use DBI ; my $cat_id = 11 ; my $dbh = DBI->connect( "DBI:CSV:f_dir=.;csv_eol=\n" ) or die "Cannot connect: " . $DBI::errstr ; my $sth = $dbh->prepare( "SELECT * from categories where id = ?" ) or die "Cannot prepare statement: " . $DBI::errstr ; print cat_list( $sth, $cat_id ), "\n" ; sub cat_list { my ( $sth, $cat_id ) = @_ ; $sth->execute( "$cat_id" ) or die "Cannot execute statement: " . $DBI::errstr ; my $data = $sth->fetchrow_hashref or die "No record found for category " . $cat_id ; return $data->{'parent'} == 0 ? $data->{'name'} : cat_list( $sth, $data->{'parent'} ) . '->' . $data->{'name'} ; } __END__
id,name,parent 1,Catalogue,0 10,Trucks,1 20,Snowmobiles,1 11,Parts,10 12,Accessories,10 21,Parts,20 22,Clothing,20
In reply to Re: Looping through a subrouting
by DamnDirtyApe
in thread Looping through a subrouting
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |