Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Pretty Printing with Data::Dumper

by halley (Prior)
on Sep 09, 2005 at 12:11 UTC ( [id://490537]=note: print w/replies, xml ) Need Help??


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 ]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://490537]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-23 20:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found