分享

perl的tell函数

 浸心阁 2015-09-08

perl的tell函数,注解都是英文,大家慢慢研读吧。

函数名 tell
调用语法 tell (filevar);
解说 返回从文件头到当前位置的距离。

Syntax
tell FILEHANDLE
tell
Definition and Usage
Returns the current position of read pointer (in bytes) within the specified FILEHANDLE. If FILEHANDLE is omitted, then it returns the position within the last file accessed.
Return Value
Current file position in bytes

Example
To check this function do the followings
    Create a text file with "this is test" as content and store it into /tmp directory.
    Read 2 charcters from this file.
    Now check the position of read pointer in the file.
 

复制代码 代码如下:
#!/usr/bin/perl -w
open( FILE, "</tmp/test.txt" ) || die "Enable to open test file";
$char = getc( FILE );
print "First Charctaer is $char\n";
$char = getc( FILE );
print "Second Charctaer is $char\n";
# Now check the poistion of read poiter.
$position = tell( FILE );
print "Position with in file $position\n";
close(FILE);

It will produce following results:

First Charctaer is T
Second Charctaer is h
Position with in file 2

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多