in reply to Re^9: Summing numbers in a file
in thread Summing numbers in a file
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 closurethat 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?