in reply to Re: Is there a problem with using barewords as filehandles ? in thread Is there a problem with using barewords as filehandles ?
As an example, one of my worst debugging sessions involved open's scope. Imagine you have a generic open_file() function in a script. The function uses a bareword FH, because whoever wrote it wasn't thinking about scope, they were just making sure a file was "open" (kinda related to the counterpoint you mentioned, that person might have learned enough to get by but not yet realize all the implications of what they were doing). Sometimes, deep in the code, you might open *another* file while processing the first one, leading to some bewildering action at a distince bugs...
Re^3: Is there a problem with using barewords as filehandles ?
by LanX (Saint) on Jul 01, 2020 at 15:23 UTC
|
> because whoever wrote it wasn't thinking about scope,
FWIW you can localize a FH inside the function's scope, but this implies some glob syntax IIRC.
I think local *FH but ...
- I'd need to look it up
- it'll localize all other vars with the same symbol, like $FH too
- it's a dynamic runtime scope not a lexical, ie don't call another sub from inside which doesn't localize the same symbol before using it
Not that beginner friendly
| [reply] [d/l] |
|