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

Re^4: Implicit closing of files

by rovf (Priest)
on Jun 17, 2008 at 14:52 UTC ( [id://692530]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Implicit closing of files
in thread Implicit closing of files

It's not that the file is left open per se. It's not that the file is left open per se. Perl ... doesn't necessarily flush buffers immediately. ... However, if you let the variable fall off the end of the scope, now you're depending on destruction to close the handle (and flush the buffer).

I think there is a contradiction in this. Of course I/O is usually flushed, but you if I understand you right, you consider it possible that the file is not open anymore (because the handle falls out of scope), but that the buffer is flushed only if the handle is destroyed (i.e. later). But this makes no sense, IMO: You can't flush a buffer to a file, if the file is already closed.

This leaves us with two possibilities: Either Perl does a proper close on the file, if the handle goes out of scope (which means that the buffer would be flushed), or that it does not close the file after the handle goes out of scope (and leaves it up to the destructor of the handle to flush the buffer and close the file, i.e. likely at program end).

The first alternative would make sense. The second alternative would mean that at the end of the block, the file is still happily open.

At least in the cases I tried, it behaved as if alternative 1 would be implemented, but I was wondering whether or not this is something I can rely to...

-- 
Ronald Fischer <ynnor@mm.st>

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-25 19:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found