|Do you know where your variables are?
Best method to capture return code from system calls?by bwelch (Curate)
|on Aug 24, 2005 at 14:25 UTC
bwelch has asked for the wisdom of the Perl Monks concerning the following question:
Using perl 5.8.0 on Solaris, I sometimes use system calls to manipulate a file or directory. This has worked well in the past, but this week a script failed trying to copy a file. The error message was "Illegal seek at ./script.pl line XXX", and the system call causing the error is here:
A friend at work said that in his experience, the return code from "system" isn't reliable when used that way. He said I should capture the actual return code from the system call and evaluate it. If it's not zero, there's an error and to print $! at that point. I followed his recommendation and the problem went away. Here's the code I used.
Could you tell me more about what is happening here and why this eliminated the errors? Also, could you offer improvements in this function for handling system calls?