2014-07-15 6 views
6

In https://stackoverflow.com/a/3220688/180275 la risposta suggerisce che (dopo un open) $^E possono essere confrontati con 0x20 per determinare se un file è utilizzato da un altro processo:

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

Ho provato e funziona. Tuttavia,, se si stampa il valore di $^E ottengo una stringa (The process cannot access the file because it is being used by another process).

Come è possibile il confronto con un numero?

Questo è su Windows.

risposta

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

Come $!, $^E è un dualvar, uno scalare che contiene due valori. Uno è una stringa e uno è un numero.

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