in reply to Re: Learning Perl - Question About Using a For Loop To Pull Data From an Array
in thread Learning Perl - Question About Using a For Loop To Pull Data From an Array
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Learning Perl - Question About Using a For Loop To Pull Data From an Array
by NetWallah (Canon) on Apr 01, 2016 at 18:44 UTC | |
|
Re^3: Learning Perl - Question About Using a For Loop To Pull Data From an Array
by Marshall (Canon) on Apr 01, 2016 at 20:33 UTC |