in reply to Nested for loop: Add arrays values in 1 set of 10
The second 'set' of your provided sample values contains 11 values. Is this a copy and paste error or intentional?
btw. you can provide split with a third argument to limit the number of values you want. So instead of using natatime() you could write:
while (my $line = <IN>) { ... my $remains = $line; while ($remains) { my (@set, $remains) = split /\t/, $remains, 11; # do something with 'sum(@set)' } }
If there are less then 11 values left, then $remains will be set to undef and the inner loop terminates on the next iteration. The last set may contain less then 10 values - split does not complain, since the provided count value is just an upper limit.
|
---|