Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: sorting entires by date

by exussum0 (Vicar)
on Jan 01, 2004 at 23:09 UTC ( #318183=note: print w/replies, xml ) Need Help??

in reply to sorting entires by date

#!/usr/bin/perl use strict; use warnings; my %file = () ; while(<>) { chop; my( $file, $width, $height, $time ) = split(/:/); $file{$time} = [ $file, $width, $height ]; } foreach ( sort keys %file ) { my $data = $file{$_}; print join(":", ( @$data, $_ ) ) . "\n"; }
Note, it doesn't work with files that have colons in them. I'm a big fan of letting the command line do stuff... so you'd run it ala.. < inFile > outFile

Play that funky music white boy..

Replies are listed 'Best First'.
Re: sorting entires by date
by Coruscate (Sexton) on Jan 01, 2004 at 23:12 UTC
    $file{$time} = [ $file, $width, $height ];

    Note that this method would break if there comes to be two rows of data in the file with the same timestamp. You'd only keep the last entry with said timestamp as the rest would be written over.

      Yup, i'm assuming unique time stamps. :) I could use file names for keys and put the sort by the time stamp.

      Play that funky music white boy..

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://318183]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2018-04-23 11:58 GMT
Find Nodes?
    Voting Booth?