The code below is to display the number of arguments entered in the command line.
#!/usr/bin/perl –w
$myVar = $#ARGV + 1;
print "Hi " , $ARGV[0] , "\n";
print "You have $myVar arguments\n";
From the perlintro, $#ARGV is a special variable which tells you the index of the last element of an array.
If this is the case, when I don't enter any value in the command line, how does $myVar value end up with 0 ?
Is it because when there is no element in the array, the index of "no element" is -1 ? As -1 + 1 = 0.