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.
|
---|
In Section
Seekers of Perl Wisdom