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

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