【问题标题】:How can $^E be compared with a number?$^E 如何与数字进行比较?
【发布时间】:2014-07-15 11:55:21
【问题描述】:

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 error-handling


    【解决方案1】:
    >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
    

    【讨论】:

      猜你喜欢
      • 2017-12-13
      • 2016-08-03
      • 1970-01-01
      • 2016-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-20
      相关资源
      最近更新 更多