Make the iterate method operate in depth-first order when called from Perl

For other use cases (like writing out the search tree) we want to go in breadth-first order.