Hey, I am working on a very basic parser. I am almost certain that my regex is correct, but values do not seem to be being stored in my $1
and $2
. Am I doing something wrong? I am just looking for tips to alter my code. Thanks for any advice! Also, I am new to Perl, so if I did something wrong, I am looking to get off on the right foot and develop solid habits.
Sample line from file:
Sat 02-August-2008 20:47 - 123.112.3.209 - "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;
I am just getting the hours from the times.
foreach my $line (@lines)
{
my $match =~ /\d\d-\w+-\d{4} (\d)(\d):\d\d/;
if( $1 == 0)
{
$times[$2] = $times[$2] + 1;
}
else
{
my $time = $1.$2;
$times[$time] = $times[$time]+ 1;
}
}
print "\n";
for(my $i=0;$i<24;$i++)
{
print "$i: $times[$i]\n";
}