in reply to open, file handles and memory
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.foreach my $line (<FILE>) { # etc } my @lines = sort <FILE>; print <FILE>;
(Or use Carp and confess() rather than die.)open(FILE, "< $file") or die "Cannot read $file: $!";
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:
As long as cat understands large files, Perl understands endless pipes, and this works smoothly.open(FILE, "cat $file |") or die "Cannot read $file: $!";
|
|---|