What is _ (single underscore) in Perl without $ or @?

When used with a filetest (-X) operator the stat structure of the previous file test is used

If any of the file tests (or either the stat or lstat operator) is given the special filehandle consisting of a solitary underline, then the stat structure of the previous file test (or stat operator) is used, saving a system call.

Example:

stat($filename);  
print "Readable\n" if -r _;  
print "Writable\n" if -w _;
...

So in your example !-d _ tests whether the file last stat-ed isn’t a directory.

Update  

The unusual _ is really a typeglob *_ but with operators expecting a filehandle the * may be omitted, like <*STDIN> may be written as <STDIN>. It is found in the symbol table

print *{$main::{_}}{IO}, "\n";   # -->  IO::Handle=IO(0x2311970)

In a one-liner the *_ gets set up only after calls to stat and _ are made.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)