in reply to how to move to the first row of array after passing it through a while loop
Hello wangruonan,
Your code has the following skeletal form:
my @headers; for $a (@list) { open(my $data, ...); while (my $line = <$data>) { while (my $fields = $csv->getline( $data )) { push @headers, $fields->[$a]; } } print LOG $headers[2], "\t"; close $data; }
The obvious problem here is that once @headers contains at least 3 elements, the output will always be the same, viz., the third element!
But it’s also important to note that reading from the filehandle $data directly — my $line = <$data> — and via getline — my $fields = $csv->getline( $data ) — is a logic error. You shouldn’t need the outer while loop; re-write the inner one to traverse the whole file.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|