
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Positioning Inside a File in Perl
You can use to tell function in Perl to know the current position of a file and seek function to point a particular position inside the file.
Perl tell Function
The first requirement is to find your position within a file, which you do using the tell function −
tell FILEHANDLE tell
This returns the position of the file pointer, in bytes, within FILEHANDLE if specified, or the current default selected filehandle if none is specified.
Perl seek Function
The seek function positions the file pointer to the specified number of bytes within a file −
seek FILEHANDLE, POSITION, WHENCE
The function uses the fseek system function, and you have the same ability to position relative to three different points: the start, the end, and the current position. You do this by specifying a value for WHENCE.
Zero sets the positioning relative to the start of the file. For example, the line sets the file pointer to the 256th byte in the file.
seek DATA, 256, 0;