2012-06-01 98 views
5

Just interested:有沒有辦法在下面的代碼片段中完成Dumper的第二種形式?Data :: 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 "}]" 

回答

7

報價the docs

不要試圖調用風擋()在參數列表的子程序:

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

過濾得到由括號混淆。你的作者去 修復這個問題,但很明顯Dumper() 不知道如何命名子例程返回值 ,從而確保進一步破壞。所以不要這樣做。