Copyright © tutorialspoint.com

PERL tell Function


Syntax

tell FILEHANDLE

tell


Definition and Usage

Returns the current position of read pointer (in bytes) within the specified FILEHANDLE. If FILEHANDLE is omitted, then it returns the position within the last file accessed.

Return Value

  • Current file position in bytes

Example

To check this function do the followings

  • Create a text file with "this is test" as content and store it into /tmp directory.

  • Read 2 charcters from this file.

  • Now check the position of read pointer in the file.

#!/usr/bin/perl -w

open( FILE, "</tmp/test.txt" ) || die "Enable to open test file";
$char = getc( FILE );
print "First Charctaer is $char\n";
$char = getc( FILE );
print "Second Charctaer is $char\n";
# Now check the poistion of read poiter.
$position = tell( FILE );
print "Position with in file $position\n";
close(FILE);

It will produce following results:

First Charctaer is T
Second Charctaer is h
Position with in file 2

Copyright © tutorialspoint.com