Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Challenge: Dumping trees.

by jmcnamara (Monsignor)
on Oct 13, 2012 at 09:13 UTC ( #998828=note: print w/ replies, xml ) Need Help??


in reply to Challenge: Dumping trees.

One option may be Data::Dumper::Perltidy:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper::Perltidy; $Data::Dumper::Perltidy::ARGV = '-i=4 -boc -nopro'; my $data = [ [ [[[[["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"] ]; print Dumper $data; __END__

Which gives a structure similar to your hand manipulated example:

$VAR1 = [ [ [ [ [ [ [ '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' ] ];

The perltidy options are explained in the Perltidy manpage.

Update: actually this isn't much of an improvement over the base Data::Dumper formatting due to the -boc option but without it Perl::Tidy compacts the branches too much. So, it probably isn't useful in this case.

--
John.


Comment on Re: Challenge: Dumping trees.
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (12)
As of 2014-07-14 08:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (257 votes), past polls