Just a few tricks. Don't use chained
if statements when a hash will do:
my %month = (
Jan => 0,
Feb => 1,
...
);
# ...
$month = $month{$month}; # Could stand to use better names
In many cases it's often better to make a big regex for the entire line. A fully-expanded line-matching regex can break out all the variables you need without any leftover material that needs to be stripped off with substitutions.
Alternatively, you could use something like
Apache::ParseLog.
Also, since you've left out the brackets on your
open call, it doesn't actually error out when you expect it to. The correct way would be:
open(LOGFILE, "datafile.html") || die "Can't open file";
Further, you can actually iterate over the log file one line at a time instead of reading it all in:
foreach my $log_line (<LOGFILE>)
{
# ...
}
By the way, that commented out
#use strict; is scary. The reason you're getting errors is because you're not properly declaring your variables with
my. For example:
my $hour = param ("hour");
my $minute = param ("minute");
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.