Hello gaseous1, and welcome to the Monastery!
Consider:
14:08 >perl -wE "my @a = (1, 3, 7); say @a; say [@a]; say length[@a];" 137 ARRAY(0x53b0d0) 15 14:11 >
The length here is 15 because there are 15 characters in “ARRAY(0x53b0d0)”, the reference string seen by the length function (which evaluates its operand in scalar context). Probably, you meant:
for ($ctr = $#data_array; $ctr >= 0; $ctr--) {
although this would be better written as:
for (reverse 0 .. $#data_array) {
Update: Just to clarify: In the above code I use $#data_array rather than scalar @data_array because the former gives the highest array index, whereas the latter gives the number of elements in the array. Since Perl arrays are indexed starting at zero, attempting to access element $data_array[scalar @data_array] is usually a logic error; for example, if the array has 3 elements, $data_array[3] accesses an uninitialised element:
14:49 >perl -wE "my @x = (12, 34, 567); say $x[3];" Use of uninitialized value in say at -e line 1. 14:50 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Printing in a WHILE loop
by Athanasius
in thread Printing in a WHILE loop
by gaseous1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |