+ -
当前位置:首页 → 问答吧 → File::Tail的read和$/的疑问

File::Tail的read和$/的疑问

时间:2010-09-08

来源:互联网

现在用File::Tail,想输出包含某个关键字的输出,并用$/控制行输入符。
但自己测试,$/并没有生效。个人估计是File::Tail中没有重新$/。
请问各位怎么解决?


测试代码如下:

#!/usr/bin/perl -w

use strict;
use File::Tail;

die "$0 must have 2 args:RE FILE\n" unless @ARGV==2;
local $/=")\n";
local $|=1;
my $re=shift;
my $file=shift;
die "$file is not exist,please check!\n" unless -e $file;
my $fh=File::Tail->new("$file");
while (defined(my $line=$fh->tail)) {
        print "$line" if $line=~/$re/i;
}



因为我的输入文件格式特殊,所以用local $/=")\n";

作者: gaochong   发布时间: 2010-09-08



QUOTE:
TO BE DONE
Planned for 1.0: Using $/ instead of \n to separate "lines" (which should make it possible to read wtmp type files). Except that I discovered I have no need for that enhancement If you do, feel free to send me the patches and I'll apply them - if I feel they don't add too much processing time.



cpan上最后的一句话

作者: yybmsrs   发布时间: 2010-09-08

我确认不是$/的问题。

如下代码的$/是生效的。

#!/usr/bin/perl -w

use strict;

die "$0 must have 2 args:RE FILE\n" unless @ARGV==2;
local $/=")\n";
my $re=shift;
my $file=shift;
die "$file is not exist,please check!\n" unless -e $file;
open my $fh,"< $file" or die "$!";
while (<$fh>) {
        print "$_" if /$re/i;
}
close $fh;

作者: gaochong   发布时间: 2010-09-08

File::Tail这个包不支持$/

作者: yybmsrs   发布时间: 2010-09-08

能不能修改这个包里的$/?
该怎么解决这个问题呢?

作者: gaochong   发布时间: 2010-09-08