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.
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.)