Location : Home > Languages > Perl > Package Title : Algorithm::Accounting |
![]() |
Algorithm::Accounting - 一般的なログから解析を行う
my $fields = [qw/id author file date/]; my $groups = [[qw(author file)], [qw(author date)]]; my $data = [ [1, 'alice', '/foo.txt', '2004-05-01' ], [2, 'bob', '/foo.txt', '2004-05-03' ], [3, 'alice', '/foo.txt', '2004-05-04' ], [4, 'john ', '/foo.txt', '2004-05-04' ], [5, 'john ', [qw(/foo.txt /bar.txt], '2004-05-04' ], ]; # オブジェクト情報を与える my $acc = Algorithm::Accounting->new(fields => $fields, field_groups => $groups ); $acc->append_data($data); # Generate report to STDOUT $acc->report; # 結果を取得 my $result = $acc->result; # 特定のフィールドの結果を取得 my $author_accounting = $acc->result('author'); # 現在の結果をリセットして再スタート $acc->reset;
Algorithm::Accounting はログ解析を行う簡単な集約メソッドを提供する。データを行で受け入れ、各行は複数のフィールドがあり、各フィールドはスカラまたはリスト(配列参照)であるものとする。
基本的な使用法は、ログを全部見て、append_data() を用いて各行に追加し(行をフィールドに分割する必要はあるが)、結果を取得するために result() を呼び出すか表示するために即座に report() を呼び出す。
filed_groups パラメータ(配列参照の配列参照)を指定し、Algorithm::Accounting はこれらのグループでフィールドを処理できる。
append_data() はフィールドの数に依存して稼動するためリストフィールドを最初に与えなければならない。
Copyright 2004 by Kang-min Liu, <gugod@gugod.org>
本プログラムはフリーソフトウェアであり、Perl 本体と同等の条件で修正/再配布してもよい。
http://www.perl.com/perl/misc/Artistic.html を見よ。
![]() |
Updated : 2007/08/30 |