Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^2: New to me: What does $var = -s 'file' do?

by stevieb (Canon)
on Sep 05, 2018 at 15:40 UTC ( #1221778=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1221778]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2020-10-28 17:56 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (263 votes). Check out past polls.