- 论坛徽章:
- 0
|
本帖最后由 b4and5 于 2015-01-07 09:35 编辑
回复 3# 死水站
1: 一个是常量 SEEK_SET貌似初值没赋?
请参考seek的用法:- seek FILEHANDLE,POSITION,WHENCE
复制代码 Sets FILEHANDLE's position, just like the fseek call of stdio . FILEHANDLE may be an expression whose value gives the name of the filehandle. The values for WHENCE are 0 to set the new position in bytes to POSITION; 1 to set it to the current position plus POSITION; and 2 to set it to EOF plus POSITION, typically negative. For WHENCE you may use the constants SEEK_SET , SEEK_CUR , and SEEK_END (start of the file, current position, end of the file) from the Fcntl module. Returns 1 on success, false otherwise.
SEEK_SET,SEEK_CUR,SEEK_END应该是Fcntl模块内置的常量标示符,不需要初始化赋值
2:逻辑问题
第二个while(<$file>)读取的位置是匹配到/三/所在行的下一行,
<$file>实际上就是一个迭代器(iterator),每次读取下一行,
my $position = tell $file, 是利用tell给出当前行的位置,
然后 seek $file, $position, SEEK_SET 把迭代器定位到$position所在的位置。
|
|