in reply to Re: New to me: What does $var = -s 'file' do?
in thread New to me: What does $var = -s 'file' do?

Not quite.

-z is used to check if it's a zero-length file. It returns '' if the file is greater than zero bytes, undef if the file doesn't exist, and 1 if the file is in fact empty.

-s will return the number of bytes, including zero if file is empty:

use warnings; use strict; use feature 'say'; say -s 'size.txt'; say -s 'empty.txt'; say -z 'size.txt'; say -z 'empty.txt';


8 # -s, 8 bytes 0 # -s, empty file # -z, file has bytes 1 # -z, file is empty

Thanks AnomalousMonk for privately correcting me on the return values from -z.