Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re:x2 if (open(FH, $path)) { ? (I got the resource acquisition blues)

by grinder (Bishop)
on May 03, 2004 at 14:50 UTC ( [id://350028]=note: print w/replies, xml ) Need Help??


in reply to Re: if (open(FH, $path)) { ?
in thread if (open(FH, $path)) { ?

Note that this is a theoretical race problem. The code could potentially run the test and determine that the file is readable, writeable, whatever.

In the intervening period between the test and the moment you attempt to open the file, the permissions might have changed, or the file itself may no longer be around.

It's the classic resource acquisition problem. Sometimes, no amount of testing can tell you whether something will succeed. All you can do is try it, and see what happens. So, to a certain extent, the technique shown in the OP is the best way to go.

  • Comment on Re:x2 if (open(FH, $path)) { ? (I got the resource acquisition blues)

Replies are listed 'Best First'.
Re: Re:x2 if (open(FH, $path)) { ? (I got the resource acquisition blues)
by Ryszard (Priest) on May 03, 2004 at 14:56 UTC
    Yup, agreed, i would s/theoretical// as there is an actual risk, and it can happen...

    To handle the negative case, one could include a die handler in the open statement to make sure everything is nice and graceful.

      If I add an if (open(FH, $path) or die "$!") { doesn't that kill the application?

      I still want it to print out the rest of the webpage.

      Update2: Nevermind.
        It kills more than the if statement; if open is failing but your application isn't dying, you must be in an eval or something.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://350028]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-24 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found