in reply to rearrange lines in file
(That pop is necessary to delete the value that points one byte past the end of the file.)my @index; do {push @index, tell FIN} while <FIN>; pop @index;
Then you can read lines from the file in any order you want, using seek with elements of @index, and print them to the output file in sequence. For example, to read and print the 5th line from the input file:
(The scalar is necessary to keep <FIN> from being evaluated in print's default list context, which would read and print the rest of the input file instead of just one line.)seek FIN, $index[4], 0; print FOUT scalar <FIN>;
|
|---|