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

Re: -s test option returns differently in some cases

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


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 :(


Comment on Re: -s test option returns differently in some cases
Select or Download Code
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 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 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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (12)
As of 2014-04-24 12:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (565 votes), past polls