in reply to for each unique value in a column find the max value..need perl script
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: for each unique value in a column find the max value..need perl script
by qmenon (Initiate) on May 31, 2011 at 17:20 UTC | |
by martell (Hermit) on May 31, 2011 at 21:14 UTC | |
by qmenon (Initiate) on Jun 01, 2011 at 08:08 UTC | |
by ww (Archbishop) on Jun 01, 2011 at 01:23 UTC | |
by qmenon (Initiate) on Jun 01, 2011 at 08:24 UTC | |
by qmenon (Initiate) on Jun 01, 2011 at 08:14 UTC |