Here's a multi-field sort. What I did was to reverse the 2nd field using Sort::Fields. It's flexible. Give it try:
#!/usr/local/bin/perl use strict; use warnings; use Sort::Fields qw(fieldsort); use Data::Dumper::Concise; my(@data) = <DATA>; my @sorted_data = fieldsort [1, -2], @data; foreach my $sorted_data(@sorted_data) { print $sorted_data; } __DATA__ 0 a 1 -4.5 0 a 2 -2.5 0 b 3 1e2 1 b 4 123456 1 b 5 1e3 1 b 6 2e5 0 b 7 .00001 0 a 8 .00002 1 a 9 -.234e2 1 b 10 1e-1 0 a 12 1e-2 0 a 13 .123 0 a 14 .234 0 b 15 1.234 0 a 16 12345.6789 1 a 17 12345.6788 1 a 18 12345.6787 1 a 19 -2222 0 b 20 -2223 0 b 21 -1e1 1 b 22 -1e-1 1 b 23 -2e2 0 b 24 -2e-2 0 b 25 -3e3 0 b 26 -3e-3 0 b 27 123345.123234 0 a 28 123345.123235 0 a 29 123345.123233 0 a 30 -4.6 0 b 31 -4.7 0 b 32 -4.8 1 b 33 -4.5e1 1 a 34 1.23 1 a 35 2.345 1 b 36 345.456 1 a 37 45678.67567 0 b 38 23423422.34234234 1 a 39 123124123
Note: the minus sign in [1,-2] means reverse order. Ascending order would be a positive number. You can choose ascending order or reverse order for any of the 4 fields. And you can have as many fields as necessary.

In reply to Re: File::Sort, but is there an Array::Sort? by Khen1950fx
in thread File::Sort, but is there an Array::Sort? by Saved

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.