> Personally I really wish you had kept the changes to use lexically
> scoped filehandles.

That's fine.  I'm certainly not *against* lexically scoped indirect
filehandles--except for all the extra syllababbles of English it takes 
to *mention* them:(--provided it doesn't complicate things or introduce 
bugs, both of which at one point occurred.

I didn't introduce them because I was attempting a minimal edit.  You
will note that there are still examples there that don't do error
checking, either, nor which are necessarily use strict compliant.  If
you clutter up the logic too much, it weakens the point.  Look at
perlfunc, for example. Those are not use strict compliant either, and it
would not be good to make them so.

I nearly always use lexical handles in non-trivial programs, although in
trust I seldom do so in trivial ones.  By trivial, I mean those that don't
even have subroutines, or very few.  Occasionally I use a global handle
because I open it in one function and use it in another.  These aren't big
programs, though, nor split up into modules.  I figure for those, it's no
worse using a direct handle than it is using a direct subroutine call.  In
large programs with more structure and thus indirection, I do use indirect
handles and indirect subroutine calls (read: methods).  In short ones, 
I often do not.

There is, however, one issue that lexical filehandles seem especially prone
to.  People claim it is a feature than they get automatically closed for
you.  I am not entirely certain I agree.  In particular, I don't approve of
error checking being omitted when they get implicitly closed due to scoping
or whatnot.  That causes errors to be lost, which means the program is
buggy.  But the same thing happens with global filehandles, too, including
pre-defined ones like STDOUT.  How many people trouble to write this:

    END {
        close(STDOUT) || die "can't close STDOUT: $!";
    } 

You really should, you know.  But next to no one does.

I did add six more explicit close() calls, and a lot more error-checking
for the rest of them, too, which had often neglected it.  I feel this is
far more important than arguing about mere lexical-vs-global, since merely
changing a global to a lexical does absolutely nothing to address the 
underlying correctness bug.

Wouldn't you agree?

--tom

Reply via email to