Chinaunix
标题:
在perl中如何获得某个文件的最后几行?
[打印本页]
作者:
wanahoo
时间:
2004-01-29 15:34
标题:
在perl中如何获得某个文件的最后几行?
如果不用shell中的tail -n,用什么来实现,如果只想获取一个文件的最后几行的话?谢谢!
作者:
deathcult
时间:
2004-01-29 17:37
标题:
在perl中如何获得某个文件的最后几行?
用
$i=0;
foreach(<filehandle>
{
$i++;
print if ((总行数-$i)<n);
}
作者:
Qiang
时间:
2004-01-29 22:55
标题:
在perl中如何获得某个文件的最后几行?
用 File::ReadBackwards , CPAN
It is simple to use, memory efficient and fast. (from the module doc )
如果你要实现 tail -n 的功能, 有 File::Tail
CPAN 是你的朋友。
作者:
麻辣
时间:
2004-01-31 18:10
标题:
在perl中如何获得某个文件的最后几行?
[quote]
原帖由 "wanahoo"]如果不用shell中的tail -n,用什么来实现,如果只想获取一个文件的最后几行的话?谢谢![/quote 发表:
#///---------------------------------------------------------------------///#
# 函数名字 : readfile_s_e #
# 所需元素 : $[0]文件路径,读取的字节数,末尾移动字节数 #
# 返回结果 : 变量 #
# 用 途 : 读取文件 系统级 #
#///---------------------------------------------------------------------///#
sub readfile_s_e {
sysopen FILES, "$_[0]", O_RDONLY;
sysseek FILES, -$_[2], 2;
sysread( FILES, my $readfile_s_e, $_[1] );
close(FILES);
return ($readfile_s_e);
}
作者:
deathcult
时间:
2004-02-05 11:14
标题:
在perl中如何获得某个文件的最后几行?
如果用File::Tail,还不如用`tail`。
:)
作者:
Qiang
时间:
2004-02-05 13:30
标题:
在perl中如何获得某个文件的最后几行?
原帖由 "deathcult" 发表:
如果用File::Tail,还不如用`tail`。
:)
then we can use 'ls' instead of readdir and also 'rm' instead of 'unlink' , or better yet, do 'rm -rf' instead of going through directory recursively.
so many .. . ; )
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2