October 2004
Intermediate to advanced
336 pages
6h 27m
English
This function reads lines from standard input and outputs them sorted by length.
For each line of text, it inserts a string in a new array. This string consists of the length of the line of text, concatenated with the vertical bar ('|') character, concatenated with the index of the line of text in the original array. The program sorts the new array, and then uses the results to display the original lines in sorted order.
This depends on the fact that when Perl converts a string to a number, it stops the conversion when it hits a non-numeric character, but still returns the number converted so far. Converting these artificially ...
Read now
Unlock full access