in reply to Flock, die and statement order
If an operation dies, all the open handles are closed as part of the normal shutdown. Also, with modern perl, you can use a lexical scalar (my $foo;) and the $foo handle will be closed automatically when it goes out of scope.
It is good policy to check all interaction with the os for errors and die, retry, or otherwise handle the error.
Your nest of conditionals is unnecessarily complicated, therefore. I'd rewrite it something like this:
At any stage that dies, the file is closed. if you want to continue in spite of errors, you can replace the die clause with warn $! and last; which will have the same effect on the handle, give the same error message, but will continue at the end of the block. I didn't try to duplicate your html output for errors, but it can be inserted in the error message and CGI::Carp can send the errors to the browser.{ sysopen my $trigger, $config->{xmlpath}.'trigfile.tf', O_WRONLY | O_EXCL | O_CREAT or die $!; flock $trigger, LOCK_EX | LOCK_NB or die $!; print $trigger $/ or die $!; close $trigger or die $!; }
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Flock, die and statement order
by Ionizor (Pilgrim) on Nov 18, 2002 at 15:30 UTC | |
by iburrell (Chaplain) on Nov 19, 2002 at 00:24 UTC | |
by Ionizor (Pilgrim) on Nov 20, 2002 at 14:19 UTC |