"John W. Krahn" <[EMAIL PROTECTED]> writes:
If so, how do I let the `next' know that open has failed? That is, how do I test exit status of open function?
open() returns true on success and undef (false) when it fails.
Is it just as in shell programing ($?)?
No.
ok, then how is it done syntacticly. Wrapping the open in an
`if', I guess would be one way.
if(open(FILE,"<$file")){ do a string of things; }else{ issue warning message; return; }
Above would be one test for undefinedness...
But what if for one reason or
another I wanted to just test to see if the open() had failed.
What would that sort of test look like?
open(FILE, "<$file") or die "Failed open: $!";
if you don't mind dieing, or I often prefer using 'unless' then I don't need to worry about a dangling else, so similar to what you have above,
unless (open(FILE, "<$file")) { warn "Failed open: $!"; return; }
# code continues here on success
For your reference,
perldoc perlopentut perldoc -f open
Also note that $? is,
"The status returned by the last pipe close, backtick (‘‘) command, successful call to wait() or waitpid(), or from the system() operator."
perldoc perlop
for more about $?.
http://danconia.org
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>