-1

Observing the output of Data::Dumper, the specifiers ($VAR1, "", ;) are not explained in the CPAN documentation.

  1. What is the purpose for the $VAR1?
  2. What is the purpose for the semicolon?
  3. What is the purpose for the quotations?

Here is my output:

$VAR1 = "Snow";
$VAR1 = "Rain";
$VAR1 = "Sunny";
$VAR1 = "";
Matt Jacob
  • 6,503
  • 2
  • 24
  • 27
Minimalist
  • 963
  • 12
  • 34
  • 3
    They're explained [right at the beginning of the documentation](https://perldoc.pl/Data::Dumper#DESCRIPTION). – melpomene Sep 27 '18 at 20:16
  • Note that you can change the name of the variable used by setting `$Data::Dumper::Varname` (defaults to VAR), and remove those variables and semicolons entirely by setting `$Data::Dumper::Terse` to 1, if you don't care about being able to string-eval the result (most people don't). – Grinnz Sep 27 '18 at 20:27
  • @Grinnz this is the type of information I was looking for when talking about the data dumper. Many people want to score this question down, but they really don't understand exactly the data dumper module. – Minimalist Sep 27 '18 at 23:54
  • @Grinnz another point I asked this question to get more a practitioner point-of-view when using this module. Thanks for your input. – Minimalist Sep 28 '18 at 00:13

2 Answers2

3

The specifiers are described in the second paragraph of the DESCRIPTION:

The return value can be "eval"ed to get back an identical copy of the original reference structure.

So, you can take the string returned by Dumper and run

my $x = eval $dumped_string;
choroba
  • 231,213
  • 25
  • 204
  • 289
-1

Looks like you have an array:

my @arr = ('Snow','Rain','Sunny');
print Dumper(@arr);

When you pass the array, Dumper thinks you passed 3 separate variables. That is why you get:

$VAR1 = 'Snow';
$VAR2 = 'Rain';
$VAR3 = 'Sunny';

In order to see the array as data structure, you need to pass the reference to the array:

print Dumper(\@arr);

This will produce:

$VAR1 = [
          'Snow',
          'Rain',
          'Sunny'
        ];

The output says that you passed the reference to array with 3 elements.

Andrey
  • 1,808
  • 1
  • 16
  • 28