Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: File open issue

by MidLifeXis (Monsignor)
on Dec 19, 2012 at 19:43 UTC ( #1009614=note: print w/replies, xml ) Need Help??

in reply to File open issue

The AM has one reasonable solution, but it assumes that the only failure mode that the $nofile variable applies to is the case where the file is not readable at the time it is tested.

  • There is a race condition between the test and the open call, and
  • the file may fail to open for other reasons.

If you can live with those conditions, great. Otherwise, another solution (similar to yours) might be:

my $nofile; my $reason; my $tempfile = "$tempdir/$ENV{'REMOTE_ADDR'}"; my @tmpfile; if ( open( my $temp_fh, "<", $tempfile ) ) { @tmpfile = <$temp_fh>; close( $temp_fh ); # You don't need this, $temp_fh should be limit +ed in scope } else { $nofile = 1; $reason = $!; # update: original typo == $@ }


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1009614]
[choroba]: he's not really sick, we just got nobody to look after him today
[Discipulus]: create an account for him; we are funny baby sitters ;=) come here child, want to listen the typeglob tale?
[vrk]: choroba Oh, that's good.
[vrk]: Discipulus I don't know much about prime numbers, but wouldn't that kind of an answer be in a graduate-level number theory book?
[Discipulus]: my 8 yo daughter has two weeks of sleep disturbs.. we are gonna be crazy..
[Discipulus]: vrk i searched but found nothing: after this my math level if terribly low but i like to discuss my discovery with kind mathematicians

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2017-04-27 08:01 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (501 votes). Check out past polls.