perl的int(-M $file)是什么意思?

3

我正在查看一些旧的Perl代码,发现有人在使用以下方法比较目录中各个文件的时间戳:

int(-M $filename);

这到底是做什么的?我查看了文档中的int()条目,但找不到关于-M标志的任何信息。

1
这是file test operators之一,int()只是将结果强制转换为整数类型。 - Marc B
1
准确来说,它是“脚本启动时间减去文件修改时间,以天为单位”。 - raina77ow
perldoc -f -M(或查看在线版本 - ThisSuitIsBlackNot
1
进一步澄清,-M 不是 int() 的“标志”。就像 int(age_of($bob)) 可能会将 Bob 的年龄向下舍入到最近的整数。age_of 不是 int() 的“标志” - 相反,age_of 的输出成为 int() 的输入。 - tobyink
1个回答

3
这是一个文件测试运算符-X
  • -X FILEHANDLE
  • -X EXPR
  • -X DIRHANDLE
  • -X

    A file test, where X is one of the letters listed below. This unary operator takes one argument, either a filename, a filehandle, or a dirhandle, and tests the associated file to see if something is true about it. If the argument is omitted, tests $_ , except for -t , which tests STDIN. Unless otherwise documented, it returns 1 for true and '' for false. If the file doesn't exist or can't be examined, it returns undef and sets $! (errno). Despite the funny names, precedence is the same as any other named unary operator. The operator may be any of:

    ...
    31.  -M  Script start time minus file modification time, in days.
    

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接