Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Is there a problem with using barewords as filehandles ?

by ForgotPasswordAgain (Priest)
on Jul 01, 2020 at 14:19 UTC ( [id://11118760]=note: print w/replies, xml ) Need Help??


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...
  • Comment on Re^2: Is there a problem with using barewords as filehandles ?

Replies are listed 'Best First'.
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

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11118760]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-19 09:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found