hallikpapa has asked for the wisdom of the Perl Monks concerning the following question:
I noticed when I do a print Dumper(\@array) when the subroutine returns, that it gets a bunch of data, but it prints them like this, key on top of value, instead of like $key => $value. Is this correct? Am I pushing the data incorrectly?#!/usr/bin/perl -w use Apache::LogRegex; my $lr; my $log_format = '"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User +-Agent}i\""'; eval { $lr = Apache::LogRegex->new($log_format) }; die "Unable to parse log line: $@" if ($@); my $get_logs = ("march-logs/march-bannat.txt", "march-logs/march-logs-web2/march-bannat.txt", "march-logs/march-logs-web3/march-bannat.txt"); my $post_logs = ("march-logs/march-post.txt", "march-logs/march-logs-web2/march-post.txt", "march-logs/march-logs-web3/march-post.txt"); my %data; my %getRecords; my $postRecords; foreach ($get_logs) { my @array = &logToHash($_); } sub logToHash { my $file = $_; my %hash; my @AoH; open LOG, $file or die $!; while ( my $line_from_logfile = <LOG> ) { eval { %data = $lr->parse($line_from_logfile); }; if (%data) { push @AoH, %data; } } return @AoH; }
'"%h', 'access_log.9.gz:XX.XX.XX.XX', '%{Referer}i', '-', '%t', '[19/Mar/2009:02:03:46 -0500]', '%r', 'GET /02230909 HTTP/1.1', '%{User-Agent}i\\""', 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; FunWebPr +oducts; GTB5; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.5072 +7)', '%b', '20', '%l', '-', '%u', '-', '%>s', '302',
|
|---|