Usage of seek functions in Perl

Source: Internet
Author: User

Seek sets the current location of the file!

When a file is very large, it can be read from a specified location.
Seek filehandle, position, whence

Success returns true, failure returns false.
Position is the new position (in bytes) to read ).
Whence has three values. 0 indicates that the new position is position, 1 indicates that the current position is added with position, and 2 indicates that the position is added at the end of the file.
For example, read and print the 12 bytes of file.txt.
Open (filehandle, "<file.txt") or die "cannot open file.txt ";
Seek filehandle, 12, 0;
While (<filehandle> ){
Print;
}
Close (filehandle );

The Tell function can return the current location of the file handle for a regular file. This location can be used as a parameter to call the seek function, so that it can be moved to a location in the file.

Reference (Click here)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.