如何使用“my”在perl中声明数组和元素?

问题描述 投票:0回答:1

如果我有一个数组,请说 @test 并将数组中的项目引用为 $test[0] 等。我的语句应该是什么样子?以下之一?

my (@test,$test); # array and element
my (@test); #just the array
my ($test);
arrays perl variables element
1个回答
0
投票

这三个都有可能。如果只有一个变量,则不需要括号。此外,对不同类型的变量(数组和标量)使用相同的名称通常不是一个好主意。

my (@tests, $test);  # Better naming. Parentheses needed.
my @tests;
my $test;
© www.soinside.com 2019 - 2024. All rights reserved.