in reply to Re: Pattern Matching in Cygwin Perl vs. Win32 Perl
in thread Pattern Matching in Cygwin Perl vs. Win32 Perl
Also, leave the newline ending off the end of the die() statement. It supressses line number information. According to perlfunc, die:
If the last element of LIST does not end in a newline, the current script line number and input line number (if any) are also printed, and a newline is supplied.
Here is my favorite file opener. I have used it for a couple of years and used to routinely catch a lot of wierd errors due to my typing skills (or lack there of).
- It doesn't suppress line number info,
- It uses the three argument style for open,
- It uses one of those cool quote-like operators (qq{}),
- It uses the lower precedence or operator to avoid extra parentheses
- It uses a scalar ($fh) instead of a glob (FH) to hold the file handle and allows me to avoid local when passing file handles,
- It quotes the file name in the error message in case something wonky is going on with white space (or I screwed up the file name), and
- It looks good in my editor's syntax highlighter. :)
open my $fh, '<', $filename or die qq{Cannot open "$filename": $!}; open my $fh, '>', $filename or die qq{Cannot open "$filename": $!}; open my $fh, '>>', $filename or die qq{Cannot open "$filename": $!};
HTH,
Charles
Charles
In Section
Seekers of Perl Wisdom