这是一个代码,它给出的数字是什么,它们的含义是什么?(perl v5.20.2)
perl -E 'say -s _'
871
添加
正如我们设法发现的那样_
,这是一个文件描述符,用于存储有关对某个文件的 stat 请求的先前结果的信息,即:
print -s "file.txt";
print -r "file.txt";
相同:
print -s "file.txt";
print -r _;
好吧,运算符-s
返回有关文件大小的信息(以字节为单位)。
问题仍然存在,关于哪个文件的信息存储在_
默认值中?这是我们从这个描述符中学到的:
use strict;
use warnings;
use utf8;
print "Filesize: ". -s _,"\n".
"Is plain file: " . -f _,"\n".
"Is readable: ".(-r _ || 0),"\n".
"Is writable: ".(-w _ || 0),"\n".
"Is owned: ".(-o _ || 0), "\n".
"Is opened to a tty: ".(-t _ || 0), "\n".
"Is setuid bit: ".(-u _ || 0), "\n".
"Is setgid bit: ".(-g _ || 0), "\n".
"Is sticky bit: ".(-k _ || 0), "\n".
"Is binary: ".(-B _ || 0), "\n".
"Last modification time (days ago): ".-M _, "\n".
"Last access time (days ago): ".-A _, "\n";
分发:
Filesize: 871
Is plain file: 1
Is readable: 1
Is writable: 0
Is owned: 0
Is opened to a tty: 0
Is setuid bit: 0
Is setgid bit: 0
Is sticky bit: 0
Is binary: 0
Last modification time (days ago): 610.295925925926
Last access time (days ago): 0.121157407407407
您已经自己回答了这个问题:
由于您在程序中包含模块,它们可以进行文件访问。你只是看到了这个上诉的结果。
这与变量的工作方式类似
$!
该命令
stat
可以返回当前文件的 inode。然后,通过这个inode,你可以找到文件本身:但是由于在
stat
使用文件名调用之前,会有_
垃圾,上面的命令可能会失败。