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";
但自己测试,$/并没有生效。个人估计是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.
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;
如下代码的$/是生效的。
#!/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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28