[perl tables="products1 tree1"] my $db = $Db{products1}; my $ary = $db->query('select sku,comb_category from products1'); my $out = ''; my $code = '00000'; my $cc = '0000'; my %done; my @levels; foreach $row ( @$ary) { my ($sku, $cat) = @$row; next if $done{$cat}; my $parent = 'TOP'; my @parts = split /:/, $cat; my $combname = ''; for( my $i = 0; $i < @parts; $i++) { my $name = $parts[$i]; my $comb = join ":", @parts[0 .. $i]; my $level = $levels[$i] ||= {}; if(! $level->{$name}) { $level->{$name} = [ ++$code, $parent, ++$cc, $name, $comb ]; $parent = $cc; } else { $parent = $level->{$name}->[2]; } } } my $tdb = $Db{tree1}; $tdb->query('delete from tree1'); my @flds = qw/parent_fld child_fld name category/; my $count++; for(@levels) { my $hash = $_; for(sort keys %$hash) { my $rec = $hash->{$_}; my $code = shift @$rec; $tdb->set_slice($code, \@flds, $rec); $count++; } } return $count; [/perl]