Perl 中的 eof函数

首页 / Perl入门教程 / Perl 中的 eof函数

描述

如果下一次读取FILEHANDLE将返回文件末尾,或者FILEHANDLE未打开,则此函数返回1。

An eof without an argument uses the last file read. Using eof() with empty parentheses is very different. It refers to the pseudo file formed from the files listed on the command line and accessed via the <> operator.

语法

以下是此函数的简单语法-

无涯教程网

eof FILEHANDLE

eof()

eof

返回值

如果FILEHANDLE不在文件末尾,则此函数返回undef;如果FILEHANDLE在下次读取时报告文件末尾,则此函数返回1。

以下是显示其基本用法的示例代码-

链接:https://www.learnfk.comhttps://www.learnfk.com/perl/perl-eof.html

来源:LearnFk无涯教程网

# insert dashes just before last line of last file
while (<>) {
   if (eof()) {	# check for end of last file
      print "--------------\n";
   }
   print;
   last if eof();  # needed if we're reading from a terminal
}

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

趣谈网络协议 -〔刘超〕

MySQL实战45讲 -〔林晓斌〕

安全攻防技能30讲 -〔何为舟〕

Kafka核心源码解读 -〔胡夕〕

人人都用得上的写作课 -〔涵柏〕

手把手教你玩音乐 -〔邓柯〕

零基础GPT应用入门课 -〔林健(键盘)〕

结构思考力 · 透过结构看表达 -〔李忠秋〕

AI 应用实战课 -〔黄佳〕

好记忆不如烂笔头。留下您的足迹吧 :)