6

In https://stackoverflow.com/a/3220688/180275 the answer suggests that (after an open) $^E can be compared with 0x20 to determine if a file is being used by another process:

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

I have tried that and it works. However, if I print the value of $^E I get a string (The process cannot access the file because it is being used by another process).

How then is the comparison to a number still possible?

This is on Windows.

Community
  • 1
  • 1
René Nyffenegger
  • 39,402
  • 33
  • 158
  • 293

1 Answers1

9
>perl -E"open my $fh, '<', 'nonexistent'; say 0+$^E; say ''.$^E;"
2
The system cannot find the file specified

Like $!, $^E is a dualvar, a scalar that contains two values. One's a string, and one's a number.

>perl -E"say $^E = 0x20;"
The process cannot access the file because it is being used by another process
ikegami
  • 367,544
  • 15
  • 269
  • 518