Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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.

Replies are listed 'Best First'.
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 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 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?
marioroy At a large firm, had to awaken a security guy a few times so that nobody would catch him sleeping.
marioroy On a large dairy farm, almost went off the road with a 10 wheeler from exhaustion. On the farm, almost went off the silo with a big tractor. At the Fransiscan monastery, almost slipped off the dome while painting it.
[marioroy]: In Saudi Arabia caught fire but didn't burn. I think angels exist.
Lady_Aleena clean up after dinner finally.
[Discipulus]: uch! so we are twice lucky to have MCE..;=)
[marioroy]: Working a midnight graveyard shift, on the way home ran out of gas. just 2 minutes later somebody stops with a small tank of gas. It's wierd. There's always someone nearby for some reason.
[Lady_Aleena]: I was the one who stop[ed in the middle of a cold night to pick up a small family walking to a gas station. I got a few gallons of free gas for the round trip, and the grandmother said she'd pray for me.
[marioroy]: Folks do not know it, but MCE was ridiculously difficult. At Niagra Falls, heard a voice on enabling Grace while in the mist boat. That 10x performance is possible.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2017-05-29 08:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?