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": $!};
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.