I also like to use
warn or
die with calls that might cause odd behaviour if they fail. For example, its easy to figure out why your code failed when an
open doesn't work, but you can get some weird behaviour if you can't
close a file, and you might not be able to trace it to the
close.
(And yes, its a good idea to close file handles explicitly, rather then banking on Perl to do it for you, which it will most of the time.)
In addition to the Carp.pm module, you can also capture the __DIE__ and __WARN__ signals yourself and print extra useful
debugging information. I'm going to guess that PerlMonks
has sections on
%SIG and
caller, and I recommend you
read them for more info.
Update: A quick check reveals that %SIG
doesn't lead you anywhere useful, so I will give you a quick
overview here: the keys to the SIG hash are the signals,
like __DIE__ and __WARN__, and the values are references
to handlers. So, for example, if you wanted to print the
time that something died you would say:
%SIG{__DIE__}=sub {print STDERR localtime, "\n", @_ };
I still recommend reading the docs on this useful tool,
but that should get you started.
Update (2): Thanks chromatic for finding the docs for %SIG. They are part of perlipc.
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.