Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Sort Hash array using date

by linuxer (Curate)
on Jan 15, 2009 at 16:56 UTC ( [id://736588] : note . print w/replies, xml ) Need Help??


in reply to Sort Hash array using date

Why don't you store the values individually as keys, and format them directly when printing?

I think of a structure ordered by "logical size" of each value:

Year -> Month -> Day -> Hour -> Minute -> Second
%Date_Time = ( Year => { Month => { Day => { Hour => { Minute => { Second => 1, }, }, }, }, }, ); for my $year ( sort keys %Date_Time ) { for my $month ( sort keys %{ $Date_Time{$year} } ) { for my $day ( sort keys %{ $Date_Time{$year}->{$month} } ) { my $time_r = $Date_Time{$year}->{$month}->{$day}; for my $hour ( sort keys %$time_r ) { for my $minute ( sort keys %{ $time_r->{$hour} } ) { for my $second ( sort keys %{ $time_r->{$hour}->{$minute} } +) { printf "Date: %d-%d-%d %02d:%02d:%02d\n", $day, $month, $year, $hour, $minute, $second; } } } } }