Perl | tell() Function
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:
#!/usr/bin/perl # Opening a File in Read-only mode open(fh, "<", "Hello.txt"); $position = tell(fh); print("Position of read pointer before reading: $position"); # Reading first 10 characters from the file for($i = 0; $i < 10; $i++) { $ch = getc(fh); } $position = tell(fh); # Current position of the read pointer print("\nCurrent Position: $position"); # Closing the File close(fh); |
chevron_right
filter_none
Output:

Example 2:
#!/usr/bin/perl # Opening a File in Read-only mode open(fh, "<", "Hello.txt"); $position = tell(fh); print("Position of read pointer before reading: $position\n"); # Printing First 10 Characters print("First ten characters are: "); # Reading and printing first # 10 characters from the file for($i = 0; $i < 10; $i++) { $ch = getc(fh); print" $ch"; } $position = tell(fh); # Current position of the read pointer print("\nCurrent Position: $position"); # Closing the File close(fh); |
chevron_right
filter_none
Output:

Recommended Posts:
- Perl | uc() Function
- Perl | exp Function
- Perl | sin() Function
- Perl | ord() Function
- Perl | each() Function
- Perl | int() function
- Perl | log() Function
- Perl | oct() Function
- Perl | cos() Function
- Perl | abs() function
- Perl | hex Function
- Perl | chr() Function
- Perl | grep() Function
- Perl | split() Function
- Perl | prototype() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



