$scalarref = \$foo;
$arrayref = \@ARGV;
$hashref = \%ENV;
$coderef = \&handler;
$globref = \*foo;
看起來不難,不過下面馬上就提到陷阱,這兩個其實是一樣的:
@list = (\$a, \@b, \%c);
@list = \($a, @b, %c);
解法是用 [] 做。
$scalarref = \$foo;
$arrayref = \@ARGV;
$hashref = \%ENV;
$coderef = \&handler;
$globref = \*foo;
@list = (\$a, \@b, \%c);
@list = \($a, @b, %c);
use Math::Complex;
use Math::Polynomial::Solve qw/poly_roots/;
my @x = poly_roots(1, 0, 0, 0, 0, 2);
foreach (@x) { print $_, "\n"; }
0.929316490603147-0.675187952399881i
0.929316490603147+0.675187952399881i
-0.35496731310463-1.09247705577745i
-0.35496731310463+1.09247705577745i
-1.14869835499703