Created
October 1, 2009 20:44
-
-
Save Woody2143/199230 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# <--SNIP--> | |
my $total_files = @files; | |
my %file_data; | |
my @files_to_search; | |
my $start_file; | |
my $end_file; | |
for ( my $i = 0; $i < $total_files; $i++) { | |
# Convert the filename to a date and get epoch | |
$files[$i] =~ /(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/; | |
my $file_time = DateTime->new( year => "20$3", month => $1, day => $2, hour => $4, minute => $5, second => $6); | |
my $file_epoch = $file_time->epoch; | |
# Save the epoch as the key and the array position as the value | |
$file_data{$file_epoch} = $i; | |
# I'll call this array position later then I actually need the filename | |
} | |
#sort the hash keys and save the results in to an array | |
my @ordered_files = sort { $file_data{$a} <=> $file_data{$b} } keys %file_data; | |
## Printing the files in the hash and then print the ordered list | |
for my $key ( keys %file_data ) { | |
print "Key: $key Value: $file_data{$key}\n"; | |
} | |
print "@ordered_files\n"; | |
# <--SNIP--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment