我在 Perl 中的问题是:使用匿名列表定义 2x2 数组。将数组传递给子例程并将它们相加。返回对 sum 数组的引用并打印程序主要部分的值。
我的脚本是:
#!/usr/bin/perl
use strict;
use warnings;
my @array = ([1,2],[4,5]);
my $refarray = \@array;
print sumarray($refarray);
sub sumarray
{
$refarray = shift;
foreach (@{$refarray})
{
$refarray = ($refarray[0]->[0]+$refarray[1]->[0],$refarray[0]->[1]+$refarray[1]->[1]);
}
return $refarray;
}
我哪里错了?请帮忙。提前致谢。
I am getting the output as 0.
如果我使用use strict;
,use warnings;
我将收到错误消息
Global symbol "@refarray" requires explicit package name at line 23.
Global symbol "@refarray" requires explicit package name at line 23.
Global symbol "@refarray" requires explicit package name at line 23.
Global symbol "@refarray" requires explicit package name at line 23.
Execution aborted due to compilation errors.