$all_cats = $dbh->selectall_arrayref("SELECT category_id,name FROM $sql{catego +ries} WHERE parent=$parent_cat_id ORDER BY category_id"); #### @categories = ( { id => insert category_id value here, name => insert name value here level => level (inside a category etc.) }, { ... }, ... ); #### $indent .= "  ..."; #### $level++; #### foreach my $current_cat (sort { $a->[1] cmp $b->[1] } @{$all_cats}) { ($cat{id}, $cat{name}) = @$current_cat; push @main::categories {level=>$level,name=>$cat{name},id=>$cat{id}}; &ListCategories($indent, $cat{id}, 'y'); }