You really don't need Perl for something like this. Assuming you have access to Unix box (or a Windows box with Cygwin installed) you can do this:

Code

sort -k 4 < input_file > output_file

But if you insist on Perl, then you can do something like this:

Code

print sort my_sort <STDIN>;

sub my_sort { my @a = split /\s+/, $a; my @b = split /\s+/, $b;

return $a[3] cmp $b[3]; }

Like my first example, it's implemented as a filter. That is it reads data from standard input and writes it to standard output. Assuming the code is in a file called "my_sort", you would call it like this: