Hey, I'm working on a very simple parser. I am pretty sure my regex is correct, but the values do not seem to be stored in mine $1and $2. Am I doing something wrong? I'm just looking for tips on changing the code. Thanks for any advice! Also, I am new to Perl, so if I did something wrong, I am looking to get on the right foot and develop strong habits.
Example 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 just get hours from time to time.
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";
}
source
share