It has been frequently asked in various ways, however, I am going to ask again because I do not fully comprehend the application of @ARGV and because I have not found an answer to this issue (or, more likely, I do not understand the answers and solutions already provided).
The question is, why is nothing being read from the command-line? Also, how do I decrypt the error message,
Use of uninitialised value $name in concatenation (.) or string at ... ?
I understand that @ARGV is an array that stores command-line arguments (files). I also understand that it can be manipulated like any other array (bearing in mind index $ARGV[0] is not the same as the command-line feature of filename variable, $0). I understand that when in a while-loop, the diamond operator will automatically shift the first element of @ARGV as $ARGV[ ], having read a line at input.
What I do not understand is how to assign an element of @ARGV to a scalar variable and then print the datum. For example (code concept taken from Learning Perl),
my $name = shift @ARGV;
while (<>) {
print “The input was $name found at the start of $_\n”;
exit;
}
As the code stands, $name’s output is blank; were I to omit shift(), $name would output 0, as I believe it should, being in scalar context, but it does not answer the question of why input from the command-line is nor being accepted. Your insights will be appreciated.
Thank you.