On every operating system unless you are accumulating memory usage in your loop that pattern will work. Just be careful, operations that impose a list-context on the filehandle will slurp the whole thing into an array. So if memory is an issue, avoid the following kinds of things:
foreach my $line (<FILE>) { # etc } my @lines = sort <FILE>; print <FILE>;
Also it is a picky detail, but I find it very helpful to instead of just dying have the die message contain full context information like it recommends in perlstyle.
open(FILE, "< $file") or die "Cannot read $file: $!";
(Or use Carp and confess() rather than die.)

A probably useless tip. Occasionally you run across a situation where you want to process large files (eg 40 GB each) and Perl does not have large file support compiled in. In that case do your reads like this:

open(FILE, "cat $file |") or die "Cannot read $file: $!";
As long as cat understands large files, Perl understands endless pipes, and this works smoothly.

In reply to Re (tilly) 1: open, file handles and memory by tilly
in thread open, file handles and memory by Viking

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.