The stupid question is the question not asked | |
PerlMonks |
Re: system commandby tachyon-II (Chaplain) |
on Jun 18, 2008 at 12:44 UTC ( [id://692693]=note: print w/replies, xml ) | Need Help?? |
You can't do this (well you can but it won't DWIM):
all it does is see if system("perl 2.pl") is valid perl regardless of 1) whether the system call succeeds or fails and 2) what happens when 2.pl actually runs. A system call may confuse you because if it *succeeds* it will return 0 (false) and if it fails it will return true! Thus you can't do:
because this will die when it works! The reason is that in *nix programing if a program suceeds it exits with a value of 0. If it fails it exits with a numerical value that corresponds to the error code. In the real world, in 1.pl you would have:
And in 2.pl you would have:
Usually you would exit with the error number or exit 0 at the (sucessful) end of the script. </code>
In Section
Seekers of Perl Wisdom
|
|