Use List::Utils. Row by row, split each field by space. Use the 'order' column as a hash key, and the rest of the columns get put into an anonymous array and pushed onto your hash for that key (use a HoAoA so that you may have multiple entries per key).

Next, iterate over the keys. For each hash entry, pull a list of mtimes out of the AoA portion of the datastructure. get a max() of those values. Then replace the mtime column in the AoA with the value that max() returned.

Now move your original file (rename) to filename.bak (for example). Then open a new file for output with the original file's name, and write your structure back out again in the intended format.

This solution does hold the entire file in memory, so it wouldn't scale well to huge files. But if you were dealing with truly huge data sets you would already have a database, and updates would be as simple as an SQL statement.

If you have a question on part of the implementation, be specific as to which part eludes you, and we'll try to help.


Dave


In reply to Re: for each unique value in a column find the max value..need perl script by davido
in thread for each unique value in a column find the max value..need perl script by qmenon

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.