Saurav Ojha Saurav Ojha - 1 year ago 74
Perl Question

what does " if (!((-s<filename/filepath>) && (some condition))) " in perl do?.

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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download