|
Re: Question on approach: msg#00348perl-beginners
Chas. Owens wrote: That date format is directly sortable, so unless you have another 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/biz@xxxxxxxxxxxxxxxxxxx foo/bar/baz@xxxxxxxxxxxxxxxxxxx quux@xxxxxxxxxxxxxxxxxxx /some/path@xxxxxxxxxxxxxxxxxxx -- 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: beginners-unsubscribe@xxxxxxxx For additional commands, e-mail: beginners-help@xxxxxxxx http://learn.perl.org/
|
|
||||||||||||||||||||||||||
|
|
|
| News | Mail Home | sitemap | FAQ | advertise |