This is actually related to the earlier "Data Structure Advice" post.

I received some great advice, but now I realize I have to sort on a third column that consists of characters.

This is the code I'm using for the sort routine:

@data = numeric_sorter(2,0, @data); &print; # Print the contents of the array sub print { foreach my $record (@data ) { for my $i (0 .. 4) { print $record->[$i] . " "; } print "\n"; } } # First sort using the 3rd element of the array(port) and if it's the +same # sort by looking at the 1st element(time) sub numeric_sorter { my ($field_num, $field_num_secondary, @data) = @_; my @sorted_items = sort { if ($a->[$field_num] != $b->[$field_num]) { $a->[$field_num] <=> $b->[$field_num] } else { $a->[$field_num_secondary] <=> $b->[$field_num_secondary] } } @data; return @sorted_items; }
Is it possible to sort the fourth col., after a tie on the first column ?
BEFORE SORT: col1 col2 col3 col4 col 5 1040564312 z 89 In 258381720 1040564312 z 89 Out 4194077715 1040564322 z 90 Out 4194081727 1040564322 z 90 In 258385268 1040564335 z 94 IN 4194085256 1040564335 z 94 Out 4194085196 DESIRED SORT: (col4) col1 col2 col3 col4 col 5 1040564312 z 89 In 258381720 1040564312 z 89 Out 4194077715 1040564322 z 90 In 258385268 1040564322 z 90 Out 4194081727 1040564335 z 94 IN 4194085256 1040564335 z 94 Out 4194085196

In reply to Sort 3X by Anonymous Monk

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.