When you submitted this question, did you see some text that said:

If something looked unlike you expected it to you might need to check out Writeup Formatting Tips

Did the node look like you expected it to? I doubt it.

To answer your question, sorting in Perl is done using the (strangely named) sort function. You might like to look at the docs for that function.

Your sort seems pretty basic. Assuming you've opened a filehandle called INPUT you can get a sorted list of records like this:

my @data = sort <INPUT>;

By the way, are those supposed to be dates. You might like to give them a closer look :)

Update: To clarify. The data does look like dates, but at least one of them is invalid. All of the others are only valid if you assume MM/DD/YYYY format. If that's the case, then sort sorted example seems a bit strange as you'd be sorting by month, then day, then year which would give bizarre results with a full set of data. Given those facts, together with the fact that the sorted example shows the data sorted in ascii-betical order, I chose to show a simple sort (that gives the right answer with the sample date) and a link to the docs for sort that would be helpful for more complex sorts.

If the data is, in fact, dates, then thinker's answer is, of course, better. However, it's a little inefficient and a Schwartzian transform might be more appropriate.

--
<http://www.dave.org.uk>

"The first rule of Perl club is you don't talk about Perl club."


In reply to Re: Sorting rows in a text file by davorg
in thread Sorting rows in a text file by saihuj

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.