perl - 如何将 $^E 与数字进行比较?

标签 perl error-handling

https://stackoverflow.com/a/3220688/180275答案表明(在 open 之后)$^E可以与 0x20 进行比较以确定文件是否正在被另一个进程使用:

open ($fh, "<", "the-file");
if ($^E == 0x20) {
  ...
}

我已经试过了,它的工作原理。但是,如果我打印 $^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

$! , $^E是一个对偶变量,一个包含两个值的标量。一个是字符串,一个是数字。
>perl -E"say $^E = 0x20;"
The process cannot access the file because it is being used by another process

关于perl - 如何将 $^E 与数字进行比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24757605/

相关文章:

python - 是否有可能从已经捕获的外部代码中捕获异常?

java - Camel 异常/错误处理事务路由,不会导致客户端异常

perl - 读取 YAML 文件后如何使用数据?

javascript - 为什么IE和Chrome中的ajax错误不同?

perl - 标量上下文中是否存在列表之类的东西?

perl - 如何获取类(class)成员的值(value)?

vbscript - 我可以在vbscript中抛出错误吗?

vba - goto block 不工作VBA

perl - Bread::Board - 注入(inject)带有 ArrayRef 类型约束的参数?

perl - 使用 perl XML::LibXML 解析