Jeff Westman wrote: > Hi, > > I need to do a sort on a couple of column ranges. > > I want to be able to do a primary sort, on say, columns 21-25 and > then a secondary sort on columns 40-49. > > Any ideas on how to approach this?
Assuming you're numbering columns from 1: @rows = sort { substr($a, 20, 5) cmp substr($b, 20, 5) || substr($a, 49, 10) cmp substr($b, 49, 10) } @rows; If you're numbering columns from 0, adjust the offsets above. The general concept for multi key sorting is to combine the comparisons with a logical "or" operation. John Krahn gave you a sort of modified "Schwartzian Transform" (did I spell that right?) approach which is faster if you have a large number of rows to process, but a bit less clear... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>