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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.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 - Fatal编程技术网

Arrays 将Perl中的差异推入数组

Arrays 将Perl中的差异推入数组,arrays,perl,Arrays,Perl,我想知道这两者有什么不同 情景1: my @something = split(someregularexpressionhere, $somethinghere); push(@{$hastable{$keyname}}, @something); 情景2: my $something = split(someregularexpressionhere, $somethinghere); push(@{$hastable{$keyname}}, $something); 在第一个场景

我想知道这两者有什么不同

情景1:

my @something = split(someregularexpressionhere, $somethinghere);
push(@{$hastable{$keyname}}, @something);   
情景2:

my $something = split(someregularexpressionhere, $somethinghere);
push(@{$hastable{$keyname}}, $something);

在第一个场景中,
split
位于数组上下文中,因此
@something
包含由拆分产生的字符串列表。在第二个场景中,
split
在标量上下文中,因此
$something
包含找到的字段数。

此外,在标量和无效上下文中,它在较旧的Perls中拆分为
@
数组。因此,如果我想将拆分的字存储到哈希表中的数组中,第一个场景是否理想?对吗?对。一般来说,我会避免在标量上下文中使用split,尽管在某些特定情况下它是有用且可读的。