Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: On timely destruction?

by theorbtwo (Prior)
on Aug 28, 2002 at 01:40 UTC ( #193331=note: print w/replies, xml ) Need Help??

in reply to On timely destruction?

I often have filehandles that escape their lexical context. To whit, I have a sub to open a file, and return the filehandle. It's called replacable parts -- for the prototype I have it open a static filename, later I have it be more configurable, with a config file, or whatever. (OK, I don't, but if I wrote cleanly, I would.)

Confession: It does an Immortal Body good.

Replies are listed 'Best First'.
Re: Re: On timely destruction?
by Elian (Parson) on Aug 28, 2002 at 01:47 UTC
    That's fine--that sort of thing is still perfectly legal and will be handled fine. The question is: Do you depend on the returned filehandle being immediately closed when the variable holding it goes out of scope? If "sooner or later, as long as it's not too much later" is OK (and the later part is on the order of milliseconds, usually), then it's not a problem and not something I need to worry about here.
      The main problem that I see is that people may do a lot of suffering from buffering. For instance in a function they write to a file. But they don't have an explicit close, so it doesn't get flushed until gc. Elsewhere you interact with the same file (perhaps you called the same function again) and get all confused when data that you know has been written, hasn't been. (And since you are sure that it has been written - a fact that you can verify by looking at it in an editor - you will look everywhere else for the problem instead...)

      Well, in the case of most of the scripts I write, no, I don't rely on timely destruction; I rarely deal with high-contention files. However, even with fairly high-contention files (and suchlike things), an unlock being a few ms late shouldn't be to terrible.

      Confession: It does an Immortal Body good.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://193331]
marioroy At a large firm, had to awaken a security guy a few times so that nobody would catch him sleeping.
marioroy On a large dairy farm, almost went off the road with a 10 wheeler from exhaustion. On the farm, almost went off the silo with a big tractor. At the Fransiscan monastery, almost slipped off the dome while painting it.
[marioroy]: In Saudi Arabia caught fire but didn't burn. I think angels exist.
Lady_Aleena clean up after dinner finally.
[Discipulus]: uch! so we are twice lucky to have MCE..;=)
[marioroy]: Working a midnight graveyard shift, on the way home ran out of gas. just 2 minutes later somebody stops with a small tank of gas. It's wierd. There's always someone nearby for some reason.
[Lady_Aleena]: I was the one who stop[ed in the middle of a cold night to pick up a small family walking to a gas station. I got a few gallons of free gas for the round trip, and the grandmother said she'd pray for me.
[marioroy]: Folks do not know it, but MCE was ridiculously difficult. At Niagra Falls, heard a voice on enabling Grace while in the mist boat. That 10x performance is possible.
[marioroy]: Lady_Aleena Angels on earth are real people. That's awesome.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2017-05-29 08:24 GMT
Find Nodes?
    Voting Booth?