此函数返回指定FILEHANDLE中读取指针的当前位置(以字节为单位)。如果省略FILEHANDLE,则它将返回上次访问的文件中的位置。
以下是此函数的简单语法-
tell FILEHANDLE tell
此函数以字节为单位返回当前文件位置。
以下是显示其基本用法的示例代码,要检查此功能,请执行以下操作-
创建一个以" this is test"为内容的文本文件,并将其存储到/tmp目录中。
链接:https://www.learnfk.comhttps://www.learnfk.com/perl/perl-tell.html
来源:LearnFk无涯教程网
从该文件读取2个字符。
现在检查读取指针在文件中的位置。
#!/usr/bin/perl -w open( FILE, "</tmp/test.txt" ) || die "Enable to open test file"; $char=getc( FILE ); print "First Character is $char\n"; $char=getc( FILE ); print "Second Character is $char\n"; # Now check the position of read pointer. $position=tell( FILE ); print "Position with in file $position\n"; close(FILE);
执行上述代码后,将产生以下输出-
First Character is E Second Character is O Position with in file 2
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Spring Boot与Kubernetes云原生微服务实践 -〔杨波〕