Perl telldir 函式



描述

此函式返回 DIRHANDLE 所引用的目錄列表中讀取指標的當前位置。這個返回值可供 seekdir() 函式使用。

語法

以下是此函式的簡單語法:-

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
perl_function_references.htm
廣告