Ren*_*ger 6 error-handling perl
在/sf/answers/225448191/中,答案表明(之后open)$^E可以与0x20进行比较,以确定另一个进程是否正在使用某个文件:
open ($fh, "<", "the-file");
if ($^E == 0x20) {
...
}
Run Code Online (Sandbox Code Playgroud)
我试过了,它的确有效.但是,如果我打印我的值得$^E到一个字符串(The process cannot access the file because it is being used by another process).
那么如何与一个数字进行比较呢?
这是在Windows上.
>perl -E"open my $fh, '<', 'nonexistent'; say 0+$^E; say ''.$^E;"
2
The system cannot find the file specified
Run Code Online (Sandbox Code Playgroud)
就像$!,$^E是一个双变量,一个包含两个值的标量.一个是字符串,一个是数字.
>perl -E"say $^E = 0x20;"
The process cannot access the file because it is being used by another process
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
108 次 |
| 最近记录: |