On Jan 25, 2005, at 8:33 AM, Bob Showalter wrote:
Rod Jenkins wrote:After a failed open, I want to run two statements for an "or die".
Code Quesiton:
open (TEST, ">/tmp/test") or { die "Could not open test file\n"; syslog("LOG_ALERT","Could not open test file"); };
This does not work, but what is the "right" way to do this? I know I could write a MyDie sub and pass a string to it.
You can't call die() before calling syslog(), since die() doesn't return. So
you need to swap those.
Then you can write it as:
open (TEST, ">/tmp/test") or do { syslog("LOG_ALERT","Could not open test file"); die "Could not open test file\n"; };
Or,
open (TEST, ">/tmp/test") or syslog("LOG_ALERT","Could not open test file"), die "Could not open test file\n";
Or,
unless (open TEST, ">/tmp/test") { syslog("LOG_ALERT","Could not open test file"); die "Could not open test file\n"; }
I should have read my example before sending, yes the syslog entry would have to come before the die. I was leaving out the "do". Thanks for the help.
Rod
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>