2016-05-04 15 views
0

fand ich die folgenden in einigen Code Perl:Was bedeutet -e in einer if-Anweisung?

if (! -e $options{"inPath"}){ 
     $logger->fatal("Directory \'$options{\"inPath\"}\' does not exist.\n"); 
} 

Was bedeutet die -e in der if Anweisung tun?

+0

'perldoc -f -e'. Es ist etwas, das Perl von 'bash' geerbt hat. – tadman

+1

Beachten Sie, dass der protokollierte Fehler (nicht vorhanden) möglicherweise falsch ist. '$!' enthält den eigentlichen Fehler. Beispielsweise verfügen Sie möglicherweise nicht über ausreichende Berechtigungen, um zu überprüfen, ob sie vorhanden sind oder nicht. – ikegami

Antwort

3

Siehe Perl file tests in der Dokumentationsstelle online perl. -e '/foo' gibt true zurück, wenn die Datei /foo existiert.

Sie können auch über die Befehlszeile darauf zugreifen, wenn Sie perldoc in Ihrem System installiert haben.

perldoc -f -X 
+2

'perldoc -f -e' funktioniert auch. – ThisSuitIsBlackNot

3

Der perldocunary Operator -e prüft, ob eine Datei vorhanden ist.


Perldoc einstellige Datei Test Operatoren Liste:

-r File is readable by effective uid/gid. 
    -w File is writable by effective uid/gid. 
    -x File is executable by effective uid/gid. 
    -o File is owned by effective uid. 
    -R File is readable by real uid/gid. 
    -W File is writable by real uid/gid. 
    -X File is executable by real uid/gid. 
    -O File is owned by real uid. 
    -e File exists. 
    -z File has zero size (is empty). 
    -s File has nonzero size (returns size in bytes). 
    -f File is a plain file. 
    -d File is a directory. 
    -l File is a symbolic link (false if symlinks aren't 
     supported by the file system). 
    -p File is a named pipe (FIFO), or Filehandle is a pipe. 
    -S File is a socket. 
    -b File is a block special file. 
    -c File is a character special file. 
    -t Filehandle is opened to a tty. 
    -u File has setuid bit set. 
    -g File has setgid bit set. 
    -k File has sticky bit set. 
    -T File is an ASCII or UTF-8 text file (heuristic guess). 
    -B File is a "binary" file (opposite of -T). 
    -M Script start time minus file modification time, in days. 
    -A Same for access time. 
    -C Same for inode change time (Unix, may differ for other 
    platforms)