Data::Dumper::Simple usage

988 views Asked by At

Just interested: Is there a way to do the second form of Dumper in this following snippet?

use Modern::Perl;
use Data::Dumper::Simple;

my $data = { name => 'jim', age => 21, updated => time() };

my $timestr = localtime($data->{updated});
say Dumper($data->{updated}, $timestr);
# output:
# $data->{updated} = 1338537112;
# $timestr = 'Fri Jun  1 08:51:52 2012';

say Dumper($data->{updated}, scalar localtime($data->{updated} ));

# compiliation error:
# say (...) interpreted as function at c:\temp\test4.pl line 9.
# syntax error at c:\temp\test4.pl line 9, near "}]"
1

There are 1 answers

0
zoul On BEST ANSWER

Quote the docs:

Do not try to call Dumper() with a subroutine in the argument list:

Dumper($foo, some_sub()); # Bad!

The filter gets confused by the parentheses. Your author was going to fix this but it became apparent that there was no way that Dumper() could figure out how to name the return values from the subroutines, thus ensuring further breakage. So don't do that.