in reply to Re: Find a pattern
in thread Find a pattern
Actually the OP's open:
open (FILE,$file) || die ("cant open file");
is correct, but old school and frowned on. As you suggest the three parameter version of open is better, but even better is to use it with a lexical file handle. Using a lexical file handle ensures the file is closed when the file handle variable goes out of scope. The improved version of open is:
open my $fileIn, "<", $file or die "Can't open $file: $!";
Note too the file name mentioned in the die and the use of $! to give the system provided failure message. Both of those can help a lot when figuring out why an open failed.
|
|---|