Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

what is -s switch checks , in the below code :

if (-s /tmp/xyz){
}

Is it something similar to :
if (-e /tmp/xyz){
}

Thanks,
Tom

Replies are listed 'Best First'.
Re: -s switch in perl
by moritz (Cardinal) on Jul 29, 2009 at 14:53 UTC
    Yes, it's also a file test operation, which returns the size of the file in byte.

    The documentation can be found by typing perldoc -f -X on the command line.

Re: -s switch in perl
by ikegami (Patriarch) on Jul 29, 2009 at 14:54 UTC
Re: -s switch in perl
by philipbailey (Curate) on Jul 29, 2009 at 17:03 UTC

    It is also worth mentioning that using -s in the manner shown is equivalent to:

    if (-e /tmp/xyz && !-z /tmp/xyz) {}

    i.e. it checks both that the file exists and has non-zero size, which can be useful.

      I think you meant to say:
      if ( -e "/tmp/xyz" && ! -z _ ) {}
      (quotes around file name, and use of "_" to re-use the most recent stat results, rather than using stat twice in a row on the same file).