my $aRequests = $hRequests{$IP}{$userAgent}{$date};
So this line would be making a "hash key" and pushing it into $aRequests
push @$aRequests, \%data;
And this line Stores the whole line from the apache log in that hash key reference that was just created?
If that is correct, I am still getting errors and I don't believe it's storing the data correctly. Mostly because it's not sending back all the data, only one line from the log. It's been so long since I've done perl. :) I'll keep hacking away and continue looking over those links. P
This is so simple, I know I have done something similar before!
Anyways, the deal is I get an uninitialized value in hash element for every line. And when I try and print the contents of @get_array, it's only one line? It looks as though $ip, $userAgent, and $date aren't being populated/created at all
foreach (@get_logs)
{
@get_array = &logToHash($_);
}
foreach(@get_array)
{
print Dumper($_);
}
sub logToHash
{
my $file = $_;
my @AoH;
open LOG, $file or die $!;
our ($aRequests,$ip,$userAgent,$date,$hRequests,$host);
while ( my $line_from_logfile = <LOG> )
{
eval { %data = $lr->parse($line_from_logfile); };
if (%data)
{
# We have data to process
while( my ($key, $value) = each(%data) )
{
if($key =~ '%h')
{
($host,$ip) = split(/:/, $value);
}
if($key =~ '%{User-Agent}i\""')
{
$userAgent = $value;
}
if($key =~ '%t')
{
$date = $value;
}
}
$aRequests = $hRequests{$ip}{$userAgent}{$date};
push @$aRequests, \%data;
}
}
return @$aRequests;
}
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.