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

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;

And

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2021-02-28 16:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?