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

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

by edwyr (Sexton)
on Sep 05, 2018 at 15:32 UTC ( #1221777=note: print w/replies, xml ) Need Help??

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

I tried to get back quickly... :) The -s is probably just a test -s testing of the argument is a zero-length file. Thanks.

Replies are listed 'Best First'.
Re^2: New to me: What does $var = -s 'file' do?
by stevieb (Canon) on Sep 05, 2018 at 15:40 UTC

    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://1221777]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2019-12-15 18:10 GMT
Find Nodes?
    Voting Booth?

    No recent polls found