Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jmcnamara (659)

jmcnamara
  (email not shown publicly)
http://search.cpan.org/author/jmcnamara/


'ere I am, J.M.! The ghost in the machine:

perl -MCPAN -e 'install jmcnamara & _ x ord $ ;' | tail -1

Journal of jmcnamara (659)

Friday January 30, 2009
05:37 AM

Data::Dumper + Perltidy

[ #38367 ]
I use Data::Dumper a lot when debugging applications that return complex data structures. However I'm not always happy with the pretty printing that Data::Dumper provides and I often find myself copying he structure into Emacs and running perltidy against it.

As such I thought that it would be nice to have a Data::Dumper::Perltidy module that would do both steps in one go. I didn't find such a module on CPAN so I wrote one.

John.
--

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • If you do

        local $Data::Dumper::Indent = 1;

    it will indent things in a regular way, not the ugly default way (described as "fancy" in the docs).

    /J

  • I was aware of it. ;-)

    From the Pod of the above module: "Data::Dumper also provides a certain level of pretty printing via the $Data::Dumper::Indent variable but it isn't quite as nice as the Perl::Tidy output".

    In particular, it doesn't do any hash element alignment on => which I find helpful when debugging.

    John.

    --

    • It was also written out of frustration with the formatting of Data::Dumper (it does alignment on => too).
      • it does alignment on => too

        Does it? I tried a few examples, including the one in the docs above, and it doesn't seem to.

        Anyway, I guess the point is that while there are several modules that dump data structures effectively (at least for my needs) there is only one module that does the pretty printing the way I want it (at times when I do want it) and that is Perl::Tidy. That is really what I was aiming for. :-)

        John.

        --

        • Does it? I tried a few examples, including the one in the docs above, and it doesn't seem to.

          Don't know. I only tried the simple test below, and it did align the => signs nicely. Maybe you are talking about something else:

          perl -MData::Dump -we "dd \%INC"

        • it does alignment on => too

          Does it? I tried a few examples, including the one in the docs above, and it doesn't seem to.

          There's also Data::Dump::Streamer [cpan.org], which does do alignment on => by default.

          The problem that I personally have with this module, is that I find its indentation levels are far too deep, it really sucks if your window is not 200 character wide.

          You have to choose between this level of indentation, or no indentation at all.