in reply to Re^3: Adding data to hashes & comparing
in thread Adding data to hashes & comparing

 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; }

Replies are listed 'Best First'.
Re^5: Adding data to hashes & comparing
by ELISHEVA (Prior) on Mar 31, 2009 at 17:56 UTC

    You may have figured this out by now, but perhaps you could post some data. I'm not exactly sure what you are trying to do with if ($key =~ '%h'). %h isn't a regular expression. Did you mean if ($key eq '%h') or did you mean if ($key =~ /%h/) ? You might want to review perlop for operators and perlretut for regular expressions.

    Also don't forget that you can use if (...) {...} elsif (...) {...} for mutually exclusive conditions. Your code as written would compare against the 2nd and 3rd if once it was done with a successful match on '%h'. See perlsyn for more information.

    Finally, I think you might find debugging this a bit easier if you use strictures. Often when data doesn't end up where you expect it, its because of undefined variables floating around. Using strictures can help detect problems like that. Put the following just under the shabang line at the top of your file:

    use strict; use warnings;

    Best, beth