#!/usr/bin/perl # Sort an IMMA file into date order use strict; use warnings; use lib "/home/hc1300/hadpb/tasks/digitisation/imma/"; use IMMA; use FindBin; use Time::Local; my @Records; while ( my $Ob =imma_read( \*STDIN ) ) { push @Records, $Ob; } @Records = sort iSort @Records; foreach my $Ob (@Records) { $Ob->write( \*STDOUT ); } # Special Perl sort routine sub iSort { # Undefined dates preceed all defined dates my $aYR = $a->{YR}; unless ( defined($aYR) ) { $aYR = 0; } my $aMO = $a->{MO}; unless ( defined($aMO) ) { $aMO = 0; } my $aDY = $a->{DY}; unless ( defined($aDY) ) { $aDY = 0; } my $aHR = $a->{HR}; unless ( defined($aHR) ) { $aHR = 0; } my $bYR = $b->{YR}; unless ( defined($bYR) ) { $bYR = 0; } my $bMO = $b->{MO}; unless ( defined($bMO) ) { $bMO = 0; } my $bDY = $b->{DY}; unless ( defined($bDY) ) { $bDY = 0; } my $bHR = $b->{HR}; unless ( defined($bHR) ) { $bHR = 0; } # Compare $aYR <=> $bYR or $aMO <=> $bMO or $aDY <=> $bDY or $aHR <=> $bHR; }