How do I get a file's last modified time in Perl?

后端 未结 9 884
说谎
说谎 2020-12-13 03:36

Suppose I have a filehandle $fh. I can check its existence with -e $fh or its file size with -s $fh or a slew of additional informati

9条回答
  •  感情败类
    2020-12-13 03:59

    You need the stat call, and the file name:

    my $last_mod_time = (stat ($file))[9];
    

    Perl also has a different version:

    my $last_mod_time = -M $file;
    

    but that value is relative to when the program started. This is useful for things like sorting, but you probably want the first version.

提交回复
热议问题