With perl, there's a number of way you could do this. One obvious solution is to read each line from the file save it into a hash were key would be the t=NUMBER (without the 't=' part :) and the value is the line itself. Then you could do a simple sort by hash keys prior to writing hash values out into a destination file.

The hash may look something like this
%file_stuff = ( .... 100 => 'a line of text from the file', 132 => 'another line of text', ... );
for a file containing this data:
... t=100 a line of text from the file t=132 another line of text ...


Another way could be create an array of adequate size to accomodate all lines from your file and simply enter each line in specific spot in the array based on the t= value. (say if you've got t=10 then save the file text line in array position 10, like $file_data[9]=$file_line).

Sorry I don't have the time to write up the code... I hope you'll find it more enjoying to write the code yourself based on the hints provided here ;).

Of course, you could always use the old good 'sort' system command to sort the file without having to resort to Perl. ;-)

"There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith

In reply to Re: sorting numbers by vladb
in thread sorting numbers 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.