This behavior isn't Math::BigInt specific, but the following code breaks on the last line.
use strict;
use warnings;
use Math::BigInt;
my $a = Math::BigInt->bone;
my $b = Math::BigInt->bone;
print ($a+$b)->bfac;
This code, however, works fine:
use strict;
use warnings;
use Math::BigInt;
my $a = Math::BigInt->bone;
my $b = Math::BigInt->bone;
print scalar($a+$b)->bfac;
My question is this... why isn't scalar context imposed automatically on the left argument of "->"? AFAIK, "->" only works on scalars and (exceptionally) on typeglobs.
You need one more set of parens,
print (($a+$b)->bfac);
as your code is interpreted as,
(print ($a+$b))->bfac;
and warnings also gave you print (...) interpreted as function ..
Need a +
so it's not interpreted as arguments to print
.
print +($a+$b)->bfac;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With