1

The following script produces no output:

use File::stat;
use Time::localtime;
my $filename = 'c:\testfile';
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
              $atime,$mtime,$ctime,$blksize,$blocks)
                  = stat($filename);
print("$mtime");

c:\testfile exists.

I've seen several answers on SO -- this, for example -- which seem to suggest that the array returned by stat() should have something meaningful in it, but I haven't seen that to be the case in practice.

This is 64 bit ActivePerl on Windows 7.

Does stat not do what those answers seemed to imply, or do Perl's file date/time functions not work under Windows (or 64 bit Windows, or some such?)

4

2 回答 2

7

This works fine:

#!perl

use strict;
use warnings;

my $filename = 'c:\Users\username\Documents\asdf23rasdf.pl';
my ($dev,  $ino,   $mode,  $nlink, $uid,     $gid, $rdev,
    $size, $atime, $mtime, $ctime, $blksize, $blocks
) = stat($filename);
print($mtime);

As alluded to in the comments - Perl's built-in stat works like the above. You don't need to use File::Stat or File::stat in order to do that. They just provide different interfaces to the same functionality.

If you want to do it with File::stat it goes like this:

use File::stat;

my $filename = 'c:\Users\username\Documents\asdf23rasdf.pl';
my $stats = stat($filename);
print( $stats -> mtime);
于 2015-02-09T21:49:44.027 回答
6

File::stat 替换stat为具有不同界面的文件。适当地删除use File::stat;或使用它stat

于 2015-02-09T21:47:34.363 回答