Copyright © tutorialspoint.com

PERL telldir Function


Syntax

telldir DIRHANDLE


Definition and Usage

Returns the current position of read pointer within the directory listing referred to by DIRHANDLE. This returned value can be used by seekdir() function.

Return Value

  • Current position within the directory.

Example

In this example we have only two files in /tmp directory.

#!/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);

It will produce following results:

Position without read : 0
Position after one read : 1220443271
test.txt
test.txt
Position after second read : 1220443271

Copyright © tutorialspoint.com