I am trying to define a variable which has a value equal to the length of an array
Easy enough, array in scalar context returns the size of the array (number of elements, the "length")
The part that is giving me trouble, I want the length to vary as I read through the array one element at a time.
WHAT? Unless you add/remove elements from the array, the size cannot change
You 're not looking for the size/length of an array
YOu 're not looking for the last index of the array
You appear to be looking for the current index of an array, in which case you have to use a c-style for-loop, or if your perl is new enough, each array
$ perl -MData::Dump -e " @f=a..c; while(@g=each @f){ dd\@g } " [0, "a"] [1, "b"] [2, "c"]
In reply to Re: Assigning the Length of an Array to a Variable (INDEX)
by Anonymous Monk
in thread Assigning the Length of an Array to a Variable
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |