Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

by eyepopslikeamosquito (Bishop)
on Jul 02, 2020 at 09:55 UTC ( #11118801=note: print w/replies, xml ) Need Help??


in reply to Is there a problem with using barewords as filehandles ?

For completeness, good ol' merlyn's classic Perl Best Practices slideshare:

  • 10.1 Filehandles (slide 136)
  • 10.2 Indirect Filehandles (slide 137)
  • 10.3 Localizing Filehandles (slide 138)
  • 10.4 Opening Cleanly (slide 139)

gives some excellent advice:

  • Don't use bareword filehandles: can't easily pass them around; can't easily localize them; can't make them "go out of scope".
  • Use indirect filehandles: they close automatically; can be passed to/from subroutines; can be stored in aggregates; might need readline or print {  } though - e.g. my $line = readline $inputs[3]; print { $output_for{$day} } @list;
  • Localizing filehandles: if you must use a package filehandle localize it; local *HANDLE; beware this also stomps on other package items ... so use it sparingly ... that's why indirect handles are better.
  • Opening cleanly: use IO::File or 3-arg open.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2020-08-10 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which rocket would you take to Mars?










    Results (58 votes). Check out past polls.

    Notices?