Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Pretty Printing with Data::Dumper

by pg (Canon)
on Sep 09, 2005 at 04:13 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://490425]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-25 14:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found