In Chapter 12, Detecting and Reporting Errors, pg 195, and example is
given of an attempt to recover from a failed open by inspecting the
values in the %! hash.  Here's an excerpt from that example:

if( $!{ENOENT} )   # File doesn't exist
  {
  warn "\tTrying to make directory $dir...\n";
  mkdir $dir, 0755;
  }
elsif( $!{ENOSPC} )  # Full disk
  {
  ....SNIP....

My question is this: wouldn't the mkdir on line 4 reset the $! value,
and also the %! hash if it failed?  If so, the rest of the checks
would be looking at the result from mkdir's failure, not the failure
of the open, correct?

If so, how would one best deal with this?  Would it be prudent to
store the failure into a scalar with something like:
my $error = grep($!{$_}, %!);

-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to