$file contains just the file name, not the path to the file. Fix:
use File::Spec::Functions qw( catfile );
opendir(my $dh, $dirname)
or die "can't opendir $dirname: $!\n";
while (defined(my $filename = readdir($dh))) {
my $fq_filename = catfile($dirname, $filename);
my $mtime = (stat($fq_filename))[9];
print "$filename: $mtime<br>";
}
closedir($dh);
I also made the following changes:
- I made the variable names more consistant ($filename is similar to $dirname).
- I converted the variables into lexicals. (How come you're not using use strict;?!)
- I converted the handles into lexicals.
- I removed the line number from the error message. You shouldn't need the line number in error messages about IO failures. You have a poor message if you do.
I didn't fix the bug where you print out plain text when HTML text is expected.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.