2014-09-24 15 views
8

此行为不是Math :: BigInt特定的,但以下代码在最后一行中断了。方法调用不提供标量上下文......看起来很奇怪

use strict; 
use warnings; 
use Math::BigInt; 

my $a = Math::BigInt->bone; 
my $b = Math::BigInt->bone; 

print ($a+$b)->bfac; 

此代码,但是,做工精细:

use strict; 
use warnings; 
use Math::BigInt; 

my $a = Math::BigInt->bone; 
my $b = Math::BigInt->bone; 

print scalar($a+$b)->bfac; 

我的问题是这样的......为什么不是标量环境上的左边参数自动施加“ - >”? AFAIK,“ - >”只适用于标量和(特殊情况下)类型球。

+0

啊,这很有道理。我应该仔细阅读警告......谢谢。 – 2014-09-24 07:12:04

回答

10

你需要一个更一套括号的,

print (($a+$b)->bfac); 

为你的代码被解释为,

(print ($a+$b))->bfac; 

和警告也给你print (...) interpreted as function ..

7

需要一个+所以它不是解释作为参数print

print +($a+$b)->bfac; 
相关问题