Chas. Owens wrote:
That date format is directly sortable, so unless you have another
reason to convert to epoch time just use a string comparison in the
sort. I would probably write the code like this:
Unfortunately, the data is not directly sortable since the date is in
American format, not Système International (SI). SI dates are directly
sortable and are the preferred format for storing dates.
I would use a heap to sort:
#!/usr/bin/perl
use strict;
use warnings;
my %data = ();
while( <DATA> ){
my ( $path, $am_date ) = split m{ \@ }msx, $_, 2;
my ( $mo, $day, $yr, $time ) = split m{ \- }msx, $am_date;
$data{$yr}{$mo}{$day}{$time} = $_;
}
print Dumper \%data;
for my $yr ( sort { $a <=> $b } keys %data ){
for my $mo ( sort { $a <=> $b } keys %{ $data{$yr} } ){
for my $day ( sort { $a <=> $b } keys %{ $data{$yr}{$mo} } ){
for my $time ( sort { $a cmp $b } keys %{ $data{$yr}{$mo}{$day} } ){
print $data{$yr}{$mo}{$day}{$time};
}
}
}
}
__DATA__
foo/bar/[email protected]
foo/bar/[email protected]
[email protected]
/some/[email protected]
--
Just my 0.00000002 million dollars worth,
Shawn
Programming is as much about organization and communication
as it is about coding.
Regardless of how small the crowd is, there is always one in
it who has to find out the hard way that the laws of physics
apply to them too.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/