How can $^E be compared with a number?

error-handling, perl

Solution

>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

Problem

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.

Original source

Related problems