Perl 中的 telldir函数

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

描述

此函数返回DIRHANDLE引用的目录列表中读指针的当前位置。此返回值可以由seekdir()函数使用。

语法

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

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

来源:LearnFk无涯教程网

telldir DIRHANDLE

返回值

此函数返回目录中的当前位置。

以下是显示其基本用法的示例代码,/tmp目录中只有两个文件-

#!/usr/bin/perl -w
opendir(DIR, "/tmp");

print("Position without read : ", telldir(DIR), "\n");

$dir=readdir(DIR);
print("Position after one read : ", telldir(DIR), "\n");
print "$dir\n";
seekdir(DIR,0);

$dir=readdir(DIR);
print "$dir\n";
print("Position after second read : " , telldir(DIR), "\n");

closedir(DIR);

执行上述代码后,将产生以下输出-

无涯教程网

Position without read : 0
Position after one read : 1
.ICE-unix
.ICE-unix
Position after second read : 1

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

技术教程推荐

赵成的运维体系管理课 -〔赵成〕

深入剖析Kubernetes -〔张磊〕

Linux性能优化实战 -〔倪朋飞〕

TensorFlow快速入门与实战 -〔彭靖田〕

Service Mesh实战 -〔马若飞〕

去无方向的信 -〔小麥〕

遗留系统现代化实战 -〔姚琪琳〕

JavaScript进阶实战课 -〔石川〕

B端体验设计入门课 -〔林远宏(汤圆)〕

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