Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays Perl使用另一个数组添加数组_Arrays_Perl_Add - Fatal编程技术网

Arrays Perl使用另一个数组添加数组

Arrays Perl使用另一个数组添加数组,arrays,perl,add,Arrays,Perl,Add,我在线浏览了下面的代码,它试图添加两个数组。有人能解释一下得到14的原因吗 my @a = (1,2,5)+(8,9); print "@a"; output: 14 输出是14,因为$a[0]是14=>5+9 +运算符在两个列表上施加标量上下文,以便获取并添加最后的元素 # in scalar context $x is assigned with last element my $x = (1,2,5); print "\$x is $x\n"; 输出$x为5 warningsprag

我在线浏览了下面的代码,它试图添加两个数组。有人能解释一下得到14的原因吗

my @a = (1,2,5)+(8,9);
print "@a";

output: 14

输出是14,因为$a[0]是14=>
5+9

+
运算符在两个列表上施加标量上下文,以便获取并添加最后的元素

# in scalar context $x is assigned with last element
my $x = (1,2,5);
print "\$x is $x\n";
输出<代码>$x为5

warnings
pragma也会抱怨,暗示有可疑的事情发生

Useless use of a constant (8) in void context
首先是:

my @a = (1,2,5)+(8,9);
在上下文中使用列表时,将返回最后一个元素。详情请咨询

因此,上述两个列表简化为:

my @a = 5 + 9;
这在数学上等于:

my @a = (14);