Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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..

Comment on Re: sorting entires by date
Select or Download Code
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2015-11-25 23:13 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (693 votes), past polls