2014-07-15 9 views
6

In https://stackoverflow.com/a/3220688/180275 schlägt vor, die Antwort, die (nach einem open) $^E mit 0x20, um zu bestimmen, ob eine Datei von einem anderen Prozess verwendet wird, verglichen werden:

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

Ich habe versucht, dass und es funktioniert. Allerdings, wenn ich den Wert $^E drucke ich bekomme eine Zeichenfolge (The process cannot access the file because it is being used by another process).

Wie ist dann der Vergleich mit einer Nummer noch möglich?

Dies ist unter Windows.

Antwort

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

Wie $!, $^E ist ein dualvar, ein Skalar, der zwei Werte enthält. Einer ist eine Schnur und einer ist eine Nummer.

>perl -E"say $^E = 0x20;" 
The process cannot access the file because it is being used by another process 
Verwandte Themen