October 2004
Intermediate to advanced
336 pages
6h 27m
English
This function merges multiple sorted files into one large sorted result. It sorts in ascending order.
The program opens all the files and stores the handles in an array. It has a corresponding array that contains the current line in each file. When the end of a file is reached, it closes the file and takes its slot out of both arrays, so the sort then proceeds with one fewer file.
The handles are stored in variable names, but other than that, reading from the file is as usual in Perl. An assignment from the handle to a string reads a single line into the string, as shown in the following line:
$firstline = <$thishandle>; ...
Read now
Unlock full access