Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Pretty Printing with Data::Dumper

by pg (Canon)
on Sep 09, 2005 at 04:13 UTC ( #490425=note: print w/replies, xml ) Need Help??

in reply to Pretty Printing with Data::Dumper

If you open up the source code, you see two places that determines this:

$Indent = 2 unless defined $Indent;


if ($Indent > 0) { $s->{xpad} = " "; $s->{sep} = "\n"; }

$s->{sep} is where that line break comes from. If you change $s->{sep} to "". You got this:

$VAR1 = [ 'a', 'b', 'c' ];

The line break is gone, but you got whole bunch of blanks. Those blanks are caused by the Indent. So change Indent to 0. Now you get:

$VAR1 = ['a','b','c'];

That's what you asked for. But with setting Indent to 0, is it still needed to set $s->{"sep"} to ""? No, as that block will only be executed if Indent is greater than 0, which is no longer true. So the only thing you need to do is to set Indent to 0.

Do you need to change the source code? No, You can set Indent from your program as Ovid has showed you.

use Data::Dumper; use strict; use warnings; $Data::Dumper::Indent = 0; my $a = ["a", "b", "c"]; print Dumper($a);

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2023-01-31 14:40 GMT
Find Nodes?
    Voting Booth?

    No recent polls found