in reply to stat only gives info on . & ..

$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 didn't fix the bug where you print out plain text when HTML text is expected.

Replies are listed 'Best First'.
Re^2: stat only gives info on . & ..
by hipnoodle (Novice) on Jan 18, 2007 at 19:13 UTC
    Hey, thanks I really appeciate the help. I was assuming stat would know to work on the current directory. This will go into an html doc so that's why you see the break tag. Cheers

      I was assuming stat would know to work on the current directory.

      stat does work on the current directory. Unfortunately, the files you are listing aren't in the current directory. They are in dir $dirname. . and .. happens to exist in both the current directory and in dir $dirname, so that's why stat "worked" on them. (Well, it didn't really work, since you weren't getting info on what you thought you were getting info.)

      This will go into an html doc so that's why you see the break tag. Cheers

      The bug I pointed out isn't the tags, it's the plain text being printed along with the tags. That plain text needs to be converted to HTML (using CGI's escapeHTML or HTML::Entities's encode_entities).

      The latest thing in web-niceness is to use <br /> for XHTML compliance.

      Never mind, I guess I was thinking everybody was supposed to use XHTML now. People yelled at me loudly last time I typed <br>. Guess I misunderstood why.

      Update: strike that please!

      non-Perl: Andy Ford

        No!

        If you're creating an HTML doc, use <br>.
        If you're creating an XHTML doc, use <br/>.

        HTML and XHTML are not compatible, so it makes no sense to break HTML compliance in order to comply with XHTML when creating HTML docs.