Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
No such thing as a small change
 
PerlMonks  

Re^2: -s test option returns differently in some cases

by frogsausage (Sexton)
on Oct 14, 2013 at 08:44 UTC ( #1058147=note: print w/ replies, xml ) Need Help??


in reply to Re: -s test option returns differently in some cases
in thread -s test option returns differently in some cases

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.


Comment on Re^2: -s test option returns differently in some cases
Select or Download Code
Re^3: -s test option returns differently in some cases
by hdb (Parson) on Oct 14, 2013 at 08:48 UTC

    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://1058147]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-04-20 12:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls