Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Implicit closing of files

by Zen (Deacon)
on Jun 17, 2008 at 14:56 UTC ( [id://692532]=note: print w/replies, xml ) Need Help??


in reply to Implicit closing of files

The problem with this post is there isn't a repro (with system spec), along with the word 'occasionally.' There can be no definitive answer without this. That being said, as others suggested, set $| and close your handle to avoid race conditions.

Replies are listed 'Best First'.
Re^2: Implicit closing of files
by rovf (Priest) on Jun 18, 2008 at 08:05 UTC

    Well, actually, I was looking for an answer like Perl should guarantee proper closing of the file if the file if the local handle goes out of scope, or otherwise Perl does not guarantee that this happens. Maybe I didn't made myself clear in this respect, but the problem wasn't what to do to avoid this problem (in my case, I simply put a close in the end of the block), but whether this problem (in a correct Perl installation) is supposed to appear at all; for, in case this is something which is supposed to work, but at my colleagues system it occasionally does not work, this means that we have a fundamental problem lurking somewhere on his platform which is well worth investigating. Otherwise, in case it is really undefined behaviour in Perl, but just happens to work *usually*, there is no need to research further.

    From my understanding of Perl, I could not decide this question. The link I mentioned in an earlier post seems to suggest that this is well defined behaviour in Perl, but of course this article could also be wrong, or I could have misinterpreted it. So I was hoping that someone would know what exactly happens in Perl if a local filehandle goes out of scope. Given the length of this discussion, this seems to be a dark corner in Perl.

    Actually, it maybe has implications to other areas as well. For instance, if I have a local scalar, holding a blessed reference, and this scalar goes out of scope (and there are no accesses to this reference any more); does Perl guarantee then that the DESTROY function of this object will be executed immediately, or could it be that it is called at some later time?

    -- 
    Ronald Fischer <ynnor@mm.st>
      That's fine, but you didn't provide a sample that repros on your coworker's machine, nor say what type of machine it is. Investigation cannot happen if you do not help others help you. Even if perl defined the behavior clearly, a bug may exist (even in your code).
        The problem is that he used *my* code, and when we tried to reproduce the problem, it worked well all the time. That's why I was wondering whether this is the type of undefined behaviour which "just works well most of the time". The machines are of the same type, but he uses Perl 5.8.8, while I am using 5.8.7 and 5.10 (ActiveState always). For this reason, I was interested whether the Perl programming langauge itself defines the behaviour (i.e. whether Perl is *supposed* to close the file when the local handle goes out of scope), in which case we should persuade the problem further, or whether the behaviour is unspecified/implementation dependent, in which case it makes no sense doing further research.
        -- 
        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://692532]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-03-28 20:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found