sub depth_first { my ($n) = @_; for ($n->children()) { depth_first($_); } } sub breadth_first { my @todo = @_; while (@todo) { my $n = shift(@todo); push @todo, $n->children(); } }