Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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';

Output:

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2019-10-23 07:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?