tell() function in Perl is used to get the position of the read pointer in a File with the use of its FileHandle. If no FileHandle is passed then it returns the position within the most recent accessed file.
Syntax: tell(FileHandle)
Parameter:
FileHandle: Filehandle of the file to be accessed.
Returns: the current position of the read pointer
Example 1:
open (fh, "<" , "Hello.txt" );
$position = tell (fh);
print ( "Position of read pointer before reading: $position" );
for ( $i = 0; $i < 10; $i ++)
{
$ch = getc (fh);
}
$position = tell (fh);
print ( "\nCurrent Position: $position" );
close (fh);
|
Output:
Example 2:
open (fh, "<" , "Hello.txt" );
$position = tell (fh);
print ( "Position of read pointer before reading: $position\n" );
print ( "First ten characters are: " );
for ( $i = 0; $i < 10; $i ++)
{
$ch = getc (fh);
print " $ch" ;
}
$position = tell (fh);
print ( "\nCurrent Position: $position" );
close (fh);
|
Output:
Last Updated :
07 May, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...