http://www.perlmonks.org?node_id=1058154


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

You won't believe it but...

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

gives "Failed: No such file or directory"

print "# Command file is located at: $myAbsPathToFile\n" if (-e $myAbs +PathToFile); system("ls -l $myAbsPathToFile"); if (-s $cmd_path) {# $myAbsPathToFile) { 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). Is a hidden/builtin Perl variable messing up with it or something? Ideas?!

Sorry for the double post, I just posted in the wrong hierarchy :(

Replies are listed 'Best First'.
Re^2: -s test option returns differently in some cases
by Anonymous Monk on Oct 14, 2013 at 09:32 UTC
    Also, the shell does its own interpolation ( see system, sh ), and instead try
    system 'ls', '-l', $myAbsPathToFile;

      I just tried it and it works the same (as assumed) as my former system() call. The test result is "Good to go".

Re^2: -s test option returns differently in some cases
by Anonymous Monk on Oct 14, 2013 at 09:30 UTC

    Ideas?!

    its right about halloween

    well, the extra system is commented out, but I imagine if a sleep(1) accomplishes the same thing, you have your answer (delay)

      Sleep gives me the error again.

      Halloween you said? No wonder why my comment to the empty system() statement is # trick or treat... fix for etc.

      Let me try your syntax for system. Since system is taking an array as argument, I'm providing an array of '1' with "ls -l ...".

Re^2: -s test option returns differently in some cases
by yitzchak (Sexton) on Oct 20, 2013 at 15:42 UTC
    $! is only going to be meaningful if -s returned undef, not if it returned 0.