use strict; open (INFILE, "<filename") or die "could not open file"; open (OUTFILE, ">outfilename") or die "could not open outfile"; my $line = <INFILE>; my @record = split " ", $line; ELEMENT: while (defined $line) { my $element = $record[0]; my @array; push @array, [$line, $record[8]]; while (1) { $line = <INFILE>; @record = split " ", $line; if ($element == $record[0]) { push @array, [$line, $record[8]]; } else { #sort using psudo-Schwartzian Transform @array = map {$_->[0]} sort {$a->[1] <=> $b->[1]} @array; print OUTFILE @array; next ELEMENT; } } }
--
flounder
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How can I read multiple lines starting with the same number and put in to a nested array and print it to a file?
by opolat (Novice) on Jul 01, 2002 at 01:58 UTC |