I love that I'm always being shown quicker ways of doing this. Using Perl for this wouldn't have occurred to me, so I'm pleased I saw this today.
What it's doing:
One of the call types of the sort function takes a block as its fist parameter and a list as its second. When called this way, the block should operate on two special variables ($a and $b), returning a -1, 0 or 1 depending upon whether $a should be placed before, beside or after $b in the sorted list. The "<=>" operator does this comparison on numbers, the numbers in question being the lengths of the two variables.
The second parameter here is a read of a file handle (the syntax for this is "<filehandlename>"). When the file handle read is used with no named file handle, it reads the the contents of each parameter the script was passed in turn (or STDIN if none). Perl reads files as lists of strings, with each string being a line in the file.
What it's doing:
One of the call types of the sort function takes a block as its fist parameter and a list as its second. When called this way, the block should operate on two special variables ($a and $b), returning a -1, 0 or 1 depending upon whether $a should be placed before, beside or after $b in the sorted list. The "<=>" operator does this comparison on numbers, the numbers in question being the lengths of the two variables.
The second parameter here is a read of a file handle (the syntax for this is "<filehandlename>"). When the file handle read is used with no named file handle, it reads the the contents of each parameter the script was passed in turn (or STDIN if none). Perl reads files as lists of strings, with each string being a line in the file.
The sorted list is then printed to STDOUT.