Hi I am a beginner at perl. I came across this statement and read some of the answers in Stackoverflow that said that it checks for non-zero file size. Pls explain.
Asked
Active
Viewed 203 times
2 Answers
2
The explanation covers the -s
operator, nothing more. It returns the file's size; if it is empty, the numeric zero is interpreted as false in boolean context, while any nonzero number is true.
print "has contents" if -s "/path/to/file";
The !
is a negation, and &&
is logical "and"; so the entire expression is true when either the file is empty or the other condition is false, or both. (Remember de Morgan's laws; !(x&y) is equivalent to !x | !y.)

tripleee
- 175,061
- 34
- 275
- 318
-
1-s will also return false (specifically, undef) if the file does not exist (or is a broken link) – ysth Sep 11 '16 at 20:43