做做样子,- use utf8;
- use Encode;
- use Modern::Perl;
- use File::Slurp;
- use Date::Format;
- use List::Util qw/sum/;
- STDOUT->autoflush(1);
-
- my $jhref = load_hash( "./se/jhref.txt" );
- my $ipref = load_hash( "./se/ipref.txt" );
- my @items = load_item( "./se/wltj201906.txt" );
-
- for my $f ( sort { (stat($a))[9] <=> (stat($b))[9] } glob "*.txt" )
- {
- next unless $f =~ /(\w+)\s+(\d+)/;
- my $id = $1;
- my $text = read_file($f);
- my @count = map { $text =~ s/${_}//g } @items;
- printf "%-25s %-9s %-10s %-10s %d %d %d %d %d %d %d\n",
- encode('gbk', time2str( "%Y年%m月%d日%k:%M:%S", (stat($f))[9])),
- $id,
- exists $ipref->{$id} ? $ipref->{$id} : "-",
- exists $jhref->{$id} ? $jhref->{$id} : "-",
- @count,
- sum(@count);
- }
-
- sub load_item
- {
- my ($head) = read_file( $_[0] );
- my @items = split(/\s+/, $head);
- return grep { s/[\/\*].*// } @items[4..9];
- }
-
- sub load_hash
- {
- my @lines = read_file( $_[0] );
- my $hash = {};
- for my $e ( grep { /^(j|p)/i } @lines )
- {
- my ($head, @list) = split(/\s+/, $e);
- grep { s/\*//; $hash->{$_} = $head } @list;
- }
- return $hash;
- }
复制代码 补充结果:- 2019年06月10日 9:37:44 B096 ping220 jh89 0 5 0 0 0 0 5
- 2019年06月10日 9:37:47 B105 ping220 jh90 0 2 0 0 0 0 2
- 2019年06月10日 9:37:48 B093 ping220 - 0 7 0 0 0 0 7
- 2019年06月10日 9:41:17 B079 ping230 jh89 0 2 0 0 0 0 2
- 2019年06月10日 9:41:19 B078 ping221 jh89 0 3 0 0 0 0 3
- 2019年06月18日10:54:36 B105 ping220 jh90 0 3 0 0 0 0 3
- 2019年06月18日10:54:36 B111 ping230 jh90 0 3 0 0 0 0 3
- 2019年06月18日10:54:39 B090 ping1 jh90 0 3 0 0 0 0 3
- 2019年06月18日10:54:39 B110 - jh90 0 2 0 0 0 0 2
- 2019年06月19日20:19:59 B254 - jh0 0 3 0 1 5 0 9
- 2019年06月20日19:00:05 B074 ping221 jh89 1 2 0 0 0 0 3
- 2019年06月20日19:03:16 B074 ping221 jh89 1 1 0 0 0 0 2
复制代码 错了也不改,逃 |