gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:12:23 24 4
gpt4 key购买 nike

只是感兴趣:在下面的代码片段中,有没有办法做第二种形式的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 - Data::Dumper::简单用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10846565/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com