Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
# 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 ]

In reply to Re: Pretty Printing with Data::Dumper by halley
in thread Pretty Printing with Data::Dumper by Anonymous Monk

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (7)
    As of 2021-03-03 12:27 GMT
    Find Nodes?
      Voting Booth?
      My favorite kind of desktop background is:

      Results (78 votes). Check out past polls.