Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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..
script.pl < inFile > outFile

Play that funky music white boy..


Comment on Re: sorting entires by date
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://318183]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2014-12-21 00:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (100 votes), past polls