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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|