seekdir DIRHANDLE, POS |
设置当前位置DIRHANDLE到POS,POS的值返回telldir的前一个值。
seekdir()函数是类似:Unix的seekdir()系统调用。
0 - 失败
1 - 成功
创建一个目录testdir的 /tmp目录内,并尝试下面的例子:
#!/usr/bin/perl -w #by www.gitbook.net 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 : 1220443271
test.txt
test.txt
Position after second read : 1220443271