Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
There's more than one way to do things
 
PerlMonks  

Re: -s test option returns differently in some cases

by hippo (Chaplain)
on Oct 14, 2013 at 08:12 UTC ( #1058143=note: print w/ replies, xml ) Need Help??


in reply to -s test option returns differently in some cases

I would increase the verbosity of the error message. eg:

if (-s $myAbsPathToFile) {print "Good to go"} else {print "File $myAbsPathToFile may be empty or missing: $!"};

That way you can see that you are testing the right file and you will also see the error condition, if one exists.

It may also be that on your SuSE 11 box the file never gets created due to a permissions problem or somesuch. Do you check that it is opened correctly for writing and that the subsequent writes to it succeed?


Comment on Re: -s test option returns differently in some cases
Download Code
Re^2: -s test option returns differently in some cases
by frogsausage (Sexton) on Oct 14, 2013 at 08:19 UTC

    Thanks for the tip. Didn't thought of printing the error message.

    The error message returned on the SuSE 11/Perl 5.14.1 is "No such file or directory". At least it gives me why now. The sad thing is, if I stat the path of the file with 'ls' it gives me from your syntax (same terminal, without modifying anything) it says it can find it (correct rights, correct user and non-empty file).

    File is created in my home and my home is on nfs.

Re^2: -s test option returns differently in some cases
by frogsausage (Sexton) on Oct 14, 2013 at 08:44 UTC
    So this is the code I have:
    print "# File is located at: $myAbsPathToFile\n" if (-e $myAbsPathToFi +le); if (-s $myAbsPathToFile) { print "Good to go\n"; } else { print "# File $myAbsPathToFile is empty or missing: $!. Cannot con +tinue!\n"; exit; }
    And its output:
    # File is located at: /nfs/home/frogsausage/file # File /nfs/home/frogsausage/file is empty or missing: No such file or + directory. Cannot continue!

    Note how awkward it is: first test is saying "Can find it, it exists!", and the second says "Nope, no such file or directory". These lines are like that in the final code: no statements in between and it isn't part of a loop or anything like that.

    Edit: @hdb Indeed! I corrected typo after edit. I converted full path to variable again hence why. Thanks for the head up. Output is still the same after the typo edit.

      There is a $ missing in

      if (-s "myAbsPathToFile") {
        Indeed! I corrected typo after edit. I converted full path to variable again hence why.

        You won't believe it but...

        print "# Command file is located at: $cmd_path\n" if (-e $cmd_path); # system("ls -l $cmd_path"); if (-s $cmd_path) {# $cmd_path) { print "Good to go"; } else { print "Failed: $!"; }

        gives "Failed: No such file or directory"

        print "# Command file is located at: $cmd_path\n" if (-e $cmd_path); system("ls -l $cmd_path"); if (-s $cmd_path) {# $cmd_path) { print "Good to go"; } else { print "Failed: $!"; }

        gives "Good to go"

        Same file, same code, same everything except that extra statement in between. An empty system(""); call does the same (works). Ideas?!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2014-04-17 02:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (437 votes), past polls