in reply to Partial sort for dependency graph

As far as I can tell, you're looking for "topological sort".

Here's what I used: it's not very efficient, but good enough for my purposes.

# $set is a hashref containing all the objects you're sorting # $connections_to is a hashref containing $from => $to pairs # (i.e. $to is dependent on $from) sub toposort { my ($set,$connections_to) = @_; my @order; while (%$set) { my ($start_node) = grep {!$connections_to->{$_} || !%{$connections_to->{$_}} } val +ues %$set; if (! $start_node ) { return; # circular dependency found } push @order, $start_node; delete $set->{$start_node}; delete $connections_to->{$_}->{$start_node} for keys %$connections +_to; } return \@order; }