我有一些这样的代码:
if (!-d _ || !-o _ || ($vncUserDirUnderTmp && ($mode & 0777) != 0700)) {
raise Exception("$prog: Wrong type or access mode of $vncUserDir.\n")
}
我可以在 Perl 中找到有关 @_
和 $_
的信息,但不能单独找到有关 _
的信息。
这里的-d _
和-o _
是什么意思?
最佳答案
与filetest (-X)一起使用时运算符stat
使用之前文件测试的结构
If any of the file tests (or either the
stat
orlstat
operator) is given the special filehandle consisting of a solitary underline, then thestat
structure of the previous file test (orstat
operator) is used, saving a system call.
...
Example:stat($filename); print "Readable\n" if -r _; print "Writable\n" if -w _; ...
所以在你的例子中!-d _
测试文件是否最后 stat
-ed 不是目录。
更新
不寻常的_
确实是一个 typeglob *_
但运算符(operator)期望文件句柄 *
可以省略,例如 <*STDIN>
可以写成<STDIN>
。在符号表中找到
print *{$main::{_}}{IO}, "\n"; # --> IO::Handle=IO(0x2311970)
在一行中 *_
仅在调用stat
后才进行设置和_
已制作。
关于perl - Perl 中没有 $ 或 @ 的 _ (单下划线)是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46215052/