Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data::Dumper::Simple usage

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 "}]"
like image 536
Richard Avatar asked Jun 01 '12 08:06

Richard


1 Answers

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.

like image 137
zoul Avatar answered Nov 16 '22 21:11

zoul