#!/usr/bin/perl -w use strict; my @lines = ; # Read this file starting with the line after __DATA__ # Schwartzian Transform: my @sorted = map {$_->[0]} sort {$a->[1]<=>$b->[1]} map {[$_,/^(\d+)/]} @lines[2..$#lines]; # That is where all the work is done. # Read it from right to left, bottom up: # So first he uses an array slice to get get the data # minus the first two header rows. This is passed to # map(), which reads the first number in each row # and maps it to the row itself, that number is the COUNT. # This is put into an array ref # map() returns an array of those array refs, which is passed to sort() # sort sorts the array refs based on the second element, COUNT # and returns an array, which is passed to another map() # which extracts the first element out of the array ref # and creates the array you had in the first place, only now # it has been sorted. print @sorted; # The next line actually ends the script, and acts a marker for __DATA__ COUNT Type Error Message ------------------------------ 3 pro bad message #1 99 dis bad message #2 209 pro bad message #3 44 dis bad message #4 19 dis Bad message #5