perl – Data :: Dumper ::简单用法

前端之家收集整理的这篇文章主要介绍了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 "}]"

解决方法

报价 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.

猜你在找的Perl相关文章