Hi ajy,
Please use <code> tags around your code so that it gets displayed properly. See also How do I post a question effectively?.
Note that the core module File::stat makes stat (which beech already recommended) a bit easier to use. At the top of your program, use File::stat;, then to get a file's creation time as a UNIX timestamp, you simply need to call stat($filename)->ctime. The Perl function time will give you the current time as a UNIX timestamp, so you just need to compare them.
Since you're using readdir, note that it's necessary to prepend the directory name to the filenames that readdir returns. In your example, at the top of the program say use File::Spec::Functions qw/catfile/;, then in the loop you just need to say my $filename = catfile($dir, $FILE);. Also, it's possible to use File::Spec's no_upwards function to skip the directories . and .. instead of the regex /^\.\.?/ (Update: Although, note that this regex also causes filenames beginning with a dot to be skipped, not sure if that's what you want?).
There are other ways to list files in a directory, for example, there's glob (note that by default, that skips files whose name begin with a dot), or maybe Path::Class::Dir's children function.
One more note: you should use warnings; at the top of your script, and check the return value of opendir for errors, and I'd recommend lexical file/directory handles, as in opendir(my $dirhandle, $dir) or die "opendir $dir: $!"; - then use $dirhandle instead of DIR.
Hope this helps,
-- Hauke D
In reply to Re: To count number of files created yesterday in a directory
by haukex
in thread To count number of files created yesterday in a directory
by ajy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |