in reply to Challenge: Dumping trees.

I've spent the last couple of days trying to code this but haven't yet succeeded. Any offers?

(NOTE: I'm looking for a compact dump to a terminal; not presentation quality graphics here. Ie. I'm not looking for GraphViz or similar, so please don't tell me about those.)

Hmmm. I've seen something resembling that in Tree::Visualize, I'm sure the BOX-ing can be easily undone ... Tree::Visualize::ASCII::BoundingBox ... here is a start

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump; use Data::Rmap qw/ rmap_array /; use Tree::Visualize; use Tree::Simple; use Tree::Simple::Visitor::FromNestedArray; my $root = [ [ [ [ [[["a", "b"], "c"], ["d", "e"]], [[["f", "g"], "h"], [["i", "j"], ["k", ["l", "m"]]]], ], ["n", [[["o", "p"], "q"], ["r", "s"]]], ], ["t", ["u", "v"]], ], [["w", ["x", "y"]], "z"], ]; dd $root; rmap_array { my( $key, @rest ) = @$_; my @new; for my $one ( $key, @rest ){ push @new, '' if ref $one; push @new, $one ; } $_ = \@new; return; } $root; dd $root; my $visitor = Tree::Simple::Visitor::FromNestedArray->new(); $visitor->setArrayTree( $root ); my $tree = Tree::Simple->new(Tree::Simple->ROOT); $tree->accept($visitor); print Tree::Visualize->new( $tree, 'ASCII', 'TopDown', #~ 'Diagonal', ## fail to throw exception #~ 'LeftSide', ## fail to throw exception #~ 'RightSide', ## fail to throw exception )->draw(), "\n\n";

See also http://stackoverflow.com/questions/801740/c-how-to-draw-a-binary-tree-to-the-console which appears right on the money but I've not tested it

I really am surprised there isn't something in the GraphViz family to do this already, graph-easy can read DOT files but the output isn't exactly what you want