Thank you for your reply. As you mentioned the script works fine. This is an example from a textbook which is why it may seem odd and not look like a real world script.
I am not having any issues with the code, rather I am trying to understand how the for loop is using the $counter variable to pull out the actual number that user entered when it appears that $counter is being used as a scalar.
For example if the user enters 1 and 3 they get fred and barnet back which are the first and third items in the array respectively.
What is confusing me is why is $names $counter - 1 giving the correct values back. If the user enters 2 values, such as 1 and 3, $counter would = 2, not 1 or 3 since it is being treated as a scalar. Yet the script correctly returns the 1st and 3rd item in the array instead of the the 1st and 2nd item of the array.
Thank you for your help.
In reply to Re^2: Learning Perl - Question About Using a For Loop To Pull Data From an Array
by aUserName
in thread Learning Perl - Question About Using a For Loop To Pull Data From an Array
by aUserName
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |