If you know that every element begins with the A19\d+ (or you only care about these lines) you can filter / clean the records with a grep. You can then pipe those (matched/cleaned) items to sort (via a Schwartzian Transform) using a quick (simple) by_date subroutine.

#!/usr/bin/perl use strict; use warnings; my @data = <DATA>; print "data\n"; print @data; my @sorted = # do a little transform map { join(' ', @$_) } # join sort { &by_date($a, $b) } # sort map { [ split / /, $_ ] } # split grep { s/^A\d+ // } # clean @data; print "sorted\n"; print @sorted; sub by_date { my($a_mon,$a_day,$a_year) = split m[/], $a->[1]; my($b_mon,$b_day,$b_year) = split m[/], $b->[1]; return ($a_year <=> $b_year or $a_mon <=> $b_mon or $a_day <=> $b_ +day); } __DATA__ A19234 hostname 06/08/07 moredata moredata A19284 hostname 07/09/07 moredata moredata A19384 hostname 06/06/06 moredata moredata A19234 hostname 07/08/07 moredata moredata A19284 hostname 07/09/07 moredata moredata A19384 hostname 06/09/07 moredata moredata A19234 hostname 07/06/06 moredata moredata A19284 hostname 07/09/07 moredata moredata A19384 hostname 06/09/07 moredata moredata

I know I could have saved some characters on the sort line, but this was more aesthetically pleasing to me.

Ivan Heffner
Sr. Software Engineer
WhitePages.com, Inc.

In reply to Re: manipulating array (TMTOWTDI!) by Codon
in thread manipulating array by gavintokyo

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.