in reply to Assigning the Length of an Array to a Variable
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"]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Assigning the Length of an Array to a Variable (INDEX)
by Anonymous Monk on Aug 26, 2013 at 05:06 UTC | |
by AnomalousMonk (Archbishop) on Aug 26, 2013 at 07:20 UTC | |
by Anonymous Monk on Aug 26, 2013 at 05:41 UTC |