N
niall.macpherson
I had a problem with a script of mine and added some 'print Dumper'
calls to try to figure out what was going on. One thing I noticed is
that when I try to dump the contents of an empty array or hash I see no
output at all.
The following test code
##------------------------------------------------------------------------------------------------
use strict;
use warnings;
use Data:umper;
my @a_test = ();
print Dumper @a_test; ## Displays nothing
push @a_test , 'aval1';
print Dumper @a_test;
my %h_test = ();
print Dumper %h_test; ## Displays nothing
$h_test{hkey1} = 'hval1';
print Dumper %h_test;
exit(0);
##-----------------------------------------------------------------------------------------------
produces the following output
C:\develop\NiallPerlScripts>datadumper.pl
$VAR1 = 'aval1';
$VAR1 = 'hkey1';
$VAR2 = 'hval1';
Is there a neat way of getting round this ? I would like to continue
using Data:umper, but don't want to have to do something like
if(#@fred)
{
print Dumper @fred;
}
else
{
print Dumper '@fred is empty';
}
for every debug statement
Thanks
calls to try to figure out what was going on. One thing I noticed is
that when I try to dump the contents of an empty array or hash I see no
output at all.
The following test code
##------------------------------------------------------------------------------------------------
use strict;
use warnings;
use Data:umper;
my @a_test = ();
print Dumper @a_test; ## Displays nothing
push @a_test , 'aval1';
print Dumper @a_test;
my %h_test = ();
print Dumper %h_test; ## Displays nothing
$h_test{hkey1} = 'hval1';
print Dumper %h_test;
exit(0);
##-----------------------------------------------------------------------------------------------
produces the following output
C:\develop\NiallPerlScripts>datadumper.pl
$VAR1 = 'aval1';
$VAR1 = 'hkey1';
$VAR2 = 'hval1';
Is there a neat way of getting round this ? I would like to continue
using Data:umper, but don't want to have to do something like
if(#@fred)
{
print Dumper @fred;
}
else
{
print Dumper '@fred is empty';
}
for every debug statement
Thanks