There are at least 2 problems in this code. Here is the best version:
use strict; use warnings;
First you renamed $dir in the source code to $path , but you did not change it in the map line. Your $dir is a directory descriptor; that where GLOB (0x ...) comes from.
Secondly, all modification dates are read "Wed December 31 16:00:00 1969" because you passed the wrong path to stat . (stat($_))[9] returned an empty list (because you were looking for a file such as GLOB(0x3f9b38)status.txt instead of the correct path name), and so the hash was actually completed containing the file names as both keys and values. The first file name was the key, the second was its value, the third was the next key, and so on. localtime converts the file name to a number (with 0), and then converts the era 0 time (Jan-1-1970 0:00:00 UTC) to your time zone.
Third, it expects $path end with a directory separator, and you pass "." . You will need to go through "./" or, even better, fix it so that the function adds a separator if necessary.
Fourth, grep did nothing else and should be removed. (In the source code, he selected only certain file names, but you changed the template to suit everything.)
How it sorts file names: get_sorted_files returns a list of path names and modification times that you store in the %files hash. keys %files returns a list of keys (file names) and sorts them by numerically comparing the associated value (modification time).
source share