- 论坛徽章:
- 0
|
本帖最后由 黑色阳光_cu 于 2010-09-09 10:50 编辑
谢谢!
请问怎么实现我的需求呢? 我现在还没有能力自己编写package .
谢谢!
gaochong 发表于 2010-09-09 10:31 ![]()
- #!/usr/bin/perl
- use strict;
- use warnings;
- use File::Tail;
- die "$0 must have 2 args:RE FILE\n" unless (@ARGV==2);
- my ($re, $file) = @ARGV;
- die "$file is not exist,please check!\n" unless -e $file;
- local $/=")\n";
- local $|=1;
- my $fh=File::Tail->new("$file");
- my $chunk = "";
- while (defined (my $line = $fh->tail()))
- {
- $chunk .= $line;
- if (index($chunk, $/) != -1)
- {
- print $chunk if ($chunk =~ /$re/i);
- $chunk = "";
- }
- }
- if ($chunk ne "")
- {
- print $chunk if ($chunk =~ /$re/i);
- $chunk = "";
- }
复制代码 |
|