Perl array vs list

前端 未结 6 1217
余生分开走
余生分开走 2020-11-28 05:01

I have two data structures in Perl:

An array:

my @array2 = ( \"1\", \"2\", \"3\");

for $elem (@array2) {
    print $elem.\"\\n\";
}
<
6条回答
  •  被撕碎了的回忆
    2020-11-28 05:46

    In Perl, arrays and lists are essentially the same thing, but your second example uses neither. Square brackets surround an array reference (a scalar value), and "assigning" a scalar to an array with something like my @array = $scalar is equivalent to my @array = ($scalar). Thus, the only element of @array in your second example is an array reference.

提交回复
热议问题