Perl模块 File::Tail::Multi特定属性用法
现象:打算利用Perl的模块File::Tail::Multi实现对多个文件的实时处理,可惜程序可以启动,但就是不处理文件内容,急煞我也
用法:
[*]use File::Tail::Multi;
[*]my @_LIST_OF_FILE_PATHS = ("/path/to/one/file", "/path/to/another/file");
[*]my $rptTail = File::Tail::Multi->new(
[*] Function => \&_read_line,
[*] LastRun_File => "/path/to/app.lastrun",
[*] Files => @_LIST_OF_FILE_PATHS
[*] );
[*]sub _read_line {
[*]my $lines_ref = shift;
[*] foreach ( @{$lines_ref} ) {
[*] chomp;
[*] next if $_ =~ //;
[*] #go play, here's the line
[*] }
[*]}
要点:
Perl模块File::Tail::Multi中的属性LastRun_File指示的是一个文件,此文件记录被tail的文件最后一次的读取状态,上面指的就是“/path/to/app.lastrun”,如果此文件不存在,则Tail操作就不能完成,即使进程启动正常
解决方法:
因为LastRun_File所指示的文件不会自动生成,故需手动创建:
[*]touch /path/to/app.lastrun
再启动程序,文件开始被Tail处理,搞定!
参考资料:
http://search.cpan.org/~atripps/File-Tail-Multi-0.1/Multi.pm
页:
[1]