Before the advent of IO::File, which provides an object-oriented API for accessing files, there was no alternative to using file handles. The problem with file handles come when writing (or using) modules. If a routine in a module needs to open a file, and uses FILE for the file handle, the only way to avoid smashing some other FILE is to localize the file handle using the   local *FILE; idiom. This guarantees that any other variables named FILE will be restored at the end of the routine that does the localizing.

If you're writing a simple script, there's little reason to do this yourself. If you're writing a module, the better thing to do now is use IO::File for file access.


In reply to Re: Local(*FILE); by dws
in thread Local(*FILE); by theguvnor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.