I use a similiar technique. When debugging a CGI application, however, prints can really mess you up.
For that situation, I have a routine (below) that writes to a file. It accepts two parameters, one which is a class string, and a message string. The section string allows me to put messages in a arbitrary category (say, 'debug', 'authentication', or 'SQL'), and the text to be printed.
Each message is timestamped, and also stamped with a user ID (that's internal to me application, and could be ignored).
I also have a similiar version that use the syslog facility to write /var/log/messages.
sub debug_log
{
@_ == 2 or confess "Incorrect number of arguments";
my ($section, $action) = @_;
my $userid = 0;
my $string = 0;
$userid = $globalUserID || "<nobody>";
$string = sprintf ("%s %s %s:%s\n", scalar localtime, $userid, $sec
+tion, $action);
open (SINK, ">> /home/httpd/somedir/logfile") or confess "Can't ope
+n logfile";
print SINK $string;
close (SINK) or confess "Can't close logfile";
}
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.