in reply to Idle search for a file-read idiom
The standard idiom is a little longer:
open FH, '<', 'foobar.txt' or die "Bleah!\n$!"; frobnicate( $_ ) while <FH>; close FH;
If $fh is declared within a narrow lexical scope you don't have to worry about closing the filehandle; it will close when it falls out of scope:
{ open my $fh, '<', 'foobar.txt' or die $!; frobnicate( $_ ) while <$fh>; }
Dave
|
|---|