9

I'm using Data::Dumper to print a perl hash with configuration, which will be evaluated by another script. The problem is that it always prints $VAR = at the start of output. I tried settings the Varname parameter to empty string, but then i get $1 instead of $VAR. How do I prevent printing the variable name using Dumper?

my $params = {-PARAMS => 0} #data

local $Data::Dumper::Purity = 1;
local $Data::Dumper::Varname  = "";
print Dumper($params) ;

Prints:

$1 = {
    '-UPDATE' => 0,
}

I want to have:

{
    '-UPDATE' => 0,
}
Mariusz Jamro
  • 30,615
  • 24
  • 120
  • 162

2 Answers2

15

Simply set $Data::Dumper::Terse = 1; and it should work:

$ perl -MData::Dumper -wle '$Data::Dumper::Terse = 1; print Dumper {-PARAMS => 1}'
{
  '-PARAMS' => 1
}
Sebastian Stumpf
  • 2,761
  • 1
  • 26
  • 34
6

Or use the OO syntax:

print Data::Dumper->new([ {-PARAMS => 1 } ])->Terse(1)->Dump;
ysth
  • 96,171
  • 6
  • 121
  • 214