Perl tell Function



Description

This function 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.

Syntax

Following is the simple syntax for this function −

tell FILEHANDLE

tell

Return Value

This function returns current file position in bytes.

Example

Following is the example code showing its basic usage, 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 characters 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 Character is $char\n";
$char = getc( FILE );
print "Second Character is $char\n";
# Now check the position of read pointer.
$position = tell( FILE );
print "Position with in file $position\n";
close(FILE);

When above code is executed, it produces the following result −

First Character is E
Second Character is O
Position with in file 2
perl_function_references.htm
Advertisements