http://qs1969.pair.com?node_id=490537


in reply to Pretty Printing with Data::Dumper

# Pretty() filters Data::Dumper output to join up short related lines. # This makes it a lot easier to read a typical hash structure. # Set $Data::Dumper::Fill like you would set $Text::Wrap::columns. # sub Pretty { my @src = split(/\n/, join('', @_)); my @dst = (); my $f = $Data::Dumper::Fill || 72; my $i = 0; while ($i <= $#src) { my $l = $src[$i]; if (not $l =~ /[\[\{\(]\s*$/) { push(@dst, $l); $i++; next; } my ($p) = ($l =~ /^(\s+)/); my $j = $i+1; while ($j <= $#src) { my $n = $src[$j]; my ($q) = ($n =~ /^(\s+)/); $n =~ s/^\s+/ /; if (length($l) + length($n) >= $f) { $l = $src[$i]; last; } $l .= $n; if ($q and $p and $q eq $p) { $i = $j; last; } $j++; } push(@dst, $l); $i++; } return join("\n", @dst) . "\n"; }
I was going to add something like this to Data::Dumper so it would run if Indent==4, but the real Data::Dumper is now native code, and this kind of indent helper should be threaded into its main loop instead of as a post-process. Example output:
bless( { HANDLERS => {}, PROPERTIES => { Works => { '1003' => undef, '1006' => [ 1, 2, 3 ] }, adjectives => [ 'shiny', 'blue' ], article => 'the', noun => 'ball' }, ITEMID => 1002, DECORATIONS => { Artisan => bless( { taint => 4 }, 'Artisan' ), Architect => bless( {}, 'Architect' ), Actor => bless( {}, 'Actor' ) } }, 'Antic::Item' )

--
[ e d @ h a l l e y . c c ]