no typo protection

This can be a legitimate concern in that you will get only a run-time error instead of a compiler error, but I have yet to write code that had enough bareword file handles for this to be a problem for me.

potential clashes with other globals like package names

Is this the origin of the convention in Perl of writing file handle names in ALL UPPERCASE? I had picked that up without really knowing why, but preventing that clash (who tries to name a file handle UNIVERSAL?) seems like a good reason for the convention.

solved by placing the package in a block

Which I do in my code:

package Outer; # ... { package Outer::Inner; # ... }

I also limit this to OOP code where Outer::Inner is an internal implementation detail of Outer. Using multi-package files too much is a good way to go insane, even with Emacs' CPerl mode and speedbar for navigation.

think about what would be a better solution, which is usually a change in design

I agree with this in the case of a proliferation of file handles, but bareword file handles remain a useful tool in producing concise I/O code in a main script, while also being visually distinctive in their own way, with both ALLCAPS and different syntax highlighting from variables. This is probably why I have not had typo problems with them, now that I notice it.

this thread is in the context of giving advice to a beginner

The concern I have is the possibility of advice that works well for a beginner, but could unintentionally limit their future growth. I am unsure exactly how "always use lexical file handles" would do that, but I am suspicious of "always" and "never" in general.

almost impossible to debug because there is no way to look inside a closure
that doesn't appear to be correct

Yes, you can examine locals if you have execution stopped inside the closure, but given a CODE ref in a structure somewhere, how do you get the closed over values out of it?


In reply to Re^10: Summing numbers in a file by jcb
in thread Summing numbers in a file by pvfki

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.