Data :: Dumper ::简单用法

Ric*_*ard 5 perl data-dumper

只是感兴趣:有没有办法在下面的代码片段中做第二种形式的Dumper?

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 "}]"
Run Code Online (Sandbox Code Playgroud)

zou*_*oul 7

引用文档:

不要尝试使用参数列表中的子例程调用Dumper():

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

过滤器被括号弄糊涂了.你的作者要解决这个问题,但很明显Dumper()无法弄清楚如何从子程序中命名返回值,从而确保进一步破坏.所以不要这样做.