Introduction to the module for reading and processing large perl files

Source: Internet
Author: User

This module uses the perl array to represent a file. each row of the file corresponds to an element of the array. The first behavior element is 0, and the second response is 1 ,...
The file itself is not actually loaded into the memory, and the operations on the array elements immediately work in the file. The greatest convenience is the ability to randomly specify the rows at the beginning and end of processing.

Basic usage:

Copy codeThe Code is as follows: use Tie: File;
Tie @ array, 'tie: file', filename or die ...;
$ Array [13] = 'blah'; # line 13 of the file is now 'blah'
Print $ array [42]; # display line 42 of the file
$ N_recs = @ array; # how many records are in the file?
$ # Array-= 2; # chop two records off the end

For (@ array ){
S/PERL/Perl/g; # Replace PERL with Perl everywhere in the file
}
# These are just like regular push, pop, unshift, shift, and splice
# Could t that they modify the file in the way you would perform CT
Push @ array, new recs ...;
My $ r1 = pop @ array;
Unshift @ array, new recs ...;
My $ r2 = shift @ array;
@ Old_recs = splice @ array, 3, 7, new recs ...;
Untie @ array; # all finished

For more functions, see the document on cpan.

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.