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.

Replies are listed 'Best First'.
Re^3: -s test option returns differently in some cases
by hdb (Monsignor) on Oct 14, 2013 at 08:48 UTC

    There is a $ missing in

    if (-s "myAbsPathToFile") {

      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?!

      Indeed! I corrected typo after edit. I converted full path to variable again hence why.