Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: -s testing for empty file; works on local, but not on remote

by ikegami (Pope)
on Sep 26, 2011 at 21:10 UTC ( #927950=note: print w/ replies, xml ) Need Help??


in reply to -s testing for empty file; works on local, but not on remote

It doesn't take three screenfulls of code to demonstrate a problem with -s. Furthermore, it appears that you didn't even show the code that fails! I'm just going to offer a couple of general tips.

First, what exactly does -s return. If it's zero, that means it thinks the file exists and that it's empty. But I suspect it's returning undef, in which case $! contains an error message. Is -s returning undef, and it so, what's $!?

my $size = -s "/home/vcg/Documents/Trial/temp"; die("-s: $!") if !defined($size); if ($size) {

A common mistake is to pass paths with trailing spaces or newlines. Or improper escaping of \. Make sure the variable contains what you think it does.


Comment on Re: -s testing for empty file; works on local, but not on remote
Select or Download Code
Re^2: -s testing for empty file; works on local, but not on remote
by Jeri (Scribe) on Sep 27, 2011 at 12:57 UTC

    This is the code that fails! Well it doesn't really fail. The same code that runs on the local, runs slightly differently (because of the -s, it think) in the remote. I'll look into what it's returning. Thanks for the heads up.

      You're saying /home/vcg/Documents/Trial/temp is a path to a remote file? Sorry, it didn't look like it to me.
Re^2: -s testing for empty file; works on local, but not on remote
by Jeri (Scribe) on Sep 27, 2011 at 13:12 UTC

    Also, I pasted in the entire code, because, I'm new at perl and I'm just guessing the -s is the problem from what checking I've done with the code. I could be wrong. Maybe someone else could catch my error? That was the idea anyway.

Re^2: -s testing for empty file; works on local, but not on remote
by Jeri (Scribe) on Sep 27, 2011 at 13:26 UTC

    Okay, just checked. There is no error message, and the temp file is definitely created.

      Everything is working smoothly. Thanks for your patience and wisdom

        What was the problem?
Re^2: -s testing for empty file; works on local, but not on remote
by Jeri (Scribe) on Sep 27, 2011 at 18:57 UTC
    I'm not exactly certain, but when I started using -z, the remote program began catching my empty files like the local one.

      There is one difference:

      If you don't check for errors, errors (incl non-existent files) being returned by -s will be mistaken as empty file.

      If you don't check for errors, errors (incl non-existent files) being returned by -z will be mistaken as non-empty file.

        What exactly do you mean by 'error'? if the -s/-z can't figure if the file has anything in it or not?
        I see your point. Thanks.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2014-08-30 19:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls