I have done this, and no, it is not simple. The reason is, you have to check to see if the category has any subcategories before removing it.
In case you are wondering:
Create a new column called hasChildren. Write a script which sets hasChildren to YES or NO.
Code:
my $total_categories = $cat->count;
print "Total Categories: $total_categories<br>"; my $sth = $cat->select;
while (my $category = $sth->fetchrow_hashref) {
my $hc = ($cat->count( { FatherID => $category->{ID} } )) ? 'Yes' : 'No';
$cat->update( { haschildren => $hc }, { ID => $category->{ID} } );
}