I am trying to get the list of files sorted by modification date. I modified the sample program from *[Sort Directory and list files based on date and time](http://forums.devshed.com/perl-programming-6/sort-directory-and-list-files-based-on-date-and-time-317220.html)*  and tried to run it.

```
sub get_sorted_files {
    my $path = shift;
    opendir my($dir), $path or die "can't opendir $path: $!";
    my %hash = map {$_ => (stat($_))[9]}
               map  { "$dir$_" }
               grep { m/.*/i }
               readdir $dir;
    closedir $dir;
    return %hash;
}

my %files = get_sorted_files(".");
foreach my $keys (sort{$files{$a} <=> $files{$b}} keys %files) {
    print "$keys\t", scalar localtime($files{$keys}), "\n";
}

```

I am running this on my Windows XP 32-bit machine using [Strawberry Perl](http://en.wikipedia.org/wiki/Strawberry_Perl) version 5.12.1.0.

The directory listing on Windows is:

![alt text](https://i.stack.imgur.com/Jgs2b.png)

The output is:

![alt text](https://i.stack.imgur.com/vo7x2.png)

The output doesn't make much sense to me. What is going wrong with this piece of code and how exactly is the `foreach` loop sorting the list of files?