Chinaunix
标题:
关于处理apache日志url重复后字节相加的问题
[打印本页]
作者:
Crisewng
时间:
2013-03-08 19:08
标题:
关于处理apache日志url重复后字节相加的问题
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
my @info;
my %hash=();
my $b;
while (my $line = <DATA>) {
@info = split /\s+/,$line;
my($url,$byte) = ($info[6],$info[9]);
$hash{$url} +=$byte;
print "$url\t$hash{$url}\n";
}
__DATA__
192.168.0.151 - - [07/Nov/2012:19:47:34 +0800] "GET /php/js/messages.php?lang=en&db=&token=1b71fd2fb26e4cd28d35e229db661d0c HTTP/1.1" 200 16554
192.168.0.151 - - [07/Nov/2012:19:47:34 +0800] "GET /php/themes/pmahomme/img/logo_right.png HTTP/1.1" 200 4548
192.168.0.151 - - [07/Nov/2012:19:47:34 +0800] "GET /php/themes/pmahomme/img/input_bg.gif HTTP/1.1" 200 170
192.168.0.151 - - [07/Nov/2012:19:47:34 +0800] "GET /php/themes/dot.gif HTTP/1.1" 200 43
192.168.0.151 - - [07/Nov/2012:19:47:34 +0800] "GET /php/themes/pmahomme/img/sprites.png HTTP/1.1" 200 38291
192.168.0.151 - - [07/Nov/2012:19:47:34 +0800] "GET /php/themes/pmahomme/img/s_error.png HTTP/1.1" 200 664
192.168.0.151 - - [07/Nov/2012:19:47:34 +0800] "GET /php/themes/pmahomme/img/s_error.png HTTP/1.1" 200 629
复制代码
这个是重复的 /php/themes/pmahomme/img/s_error.png 所以想相加后边 664和629 。我这样写的结果不对,请大家棒棒忙。。
应该是用hash但是一直不知道怎么使用
作者:
Crisewng
时间:
2013-03-08 21:14
while(my($k,$v) = each %hash) {
print "$k\t$v\n";
}
解决了。。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2