in reply to Implicit closing of files

The code you supply does not compile, the asterisk is in the wrong place, should be local *HANDLE;. However, what the others are driving at is that using local on a file handle is rather dubious. With local (rather than my) the value goes out of scope, not the variable which remains a global. Nevertheless, Perl should still flush the buffer on close.

Replies are listed 'Best First'.
Re^2: Implicit closing of files
by rovf (Priest) on Jun 17, 2008 at 11:32 UTC
    The code you supply does not compile, the asterisk is in the wrong place, should be local *HANDLE;.
    Oops, you are right.
    With local (rather than my) the value goes out of scope, not the variable which remains a global.
    Does this mean that this variable would stay in the symbol table of the package, although there is no way that it can be "re-activated" later on?
    Nevertheless, Perl should still flush the buffer on close.
    I guess you mean: should still flush the buffer on block exit, since the whole point here is that we do not do an explicit close...
    -- 
    Ronald Fischer <ynnor@mm.st>
      I'm still puzzled why you are using local. Is your perl version so old that you do not have 'my' variables? Most would agree that 'local' is only used these days when altering system variables like $/, $|, and so on (OK, there may be other specialised uses, but these are rare).
      The replies here indicate that no one has the courage (me included) to say that 'local' has the desired effect, we just don't use it any more.
        I'm still puzzled why you are using local.
        Actually, I recently switched use a scoped variable of type IO::Handle, but after reading the article I mentioned in my earlier posting, which proposed using a local handle in the way described, I wanted to try it out. Let's simply call it curiosity....
        -- 
        Ronald Fischer <ynnor@mm.st>