特殊变量 $[ 表示数组的第一索引值,一般都为 0 ,如果我们将 $[ 设置为 1,则数组的第一个索引值即为 1,第二个为 2,以此类推。

举例:

[root@localhost shell]# cat hello.pl 
#!/usr/bin/perl
@test=qw(huang bao kang);
print "@test\n";

$[=1;
print "$test[1]\n";
print "$test[2]\n";

运行结果如下:

[root@localhost shell]# ./hello.pl 
Use of assignment to $[ is deprecated at ./hello.pl line 5.
huang bao kang
huang
bao

新版会提示已废弃的使用。