in reply to Re^2: How to store the indexes of a array
in thread How to store the indexes of a array
It doesn't sound to me like you want the indices of the array, but the actual values. When you use foreach (or for) with a scalar followed by an array, that's what you get. So you can just go ahead and use the values in your formula:
foreach my $value (@data) { $var = 1/($count-1); $variance = $var*(($value-$Average)**2); }
If you actually need the indices, you can use a C-style for loop or the range operator, in both cases letting the scalar value of the array represent the number of elements in it:
for( my $i=0; $i < @data; $i++ ){ # do something with $data[$i] } # or for my $i (0..(@data-1)){ # do something with $data[$i] }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How to store the indexes of a array
by anonym (Acolyte) on Oct 14, 2011 at 23:33 UTC |