出处:http://yesho.blogbus.com/logs/10279644.html
$#作为一个变量表示打印数字时默认的数字输出格式,后面加上ARGV又表示什么意思呢?
遇到perl的问题首先查perldoc,在perlvar里查到关于@ARGV的一条: The array @ARGV contains the command-line arguments intended for the script. $#ARGV is generally the number of arguments minus one, because $ARGV[0] is the first argument, not the program's command name itself. See $0 for the command name.
可以看出,$#ARGV为命令行参数(不包括命令本身)的个数减一,即数组@ARGV最后一个元素的索引。用处也就是在程序开始时判断命令行参数个数,或者直接操作最后一个命令行参数。
本质上,$#加数组名表示数组最后一个元素的索引,其实,这种糟糕的语法来源于C Shell,在实际的代码中不常见。判断命令行参数个数,可以把@ARGV用在标量上下文中,直接操作最后一个数组元素,可以利用负数索引值。(参见 《perl语言入门》3.2 特殊的数组索引)