Tie::FileSection - restrict files sequential access using array like boundaries
version 0.171861
use Tie::FileSection; my $filename = 'some/text/file.txt'; #Lines are indexed starting from 1 my $Header = Tie::FileSection->new( filename => $filename, first_line => 1, last_line => 1 ); say "Header========"; say <$Header>; my $Content = Tie::FileSection->new( filename => $filename, first_line =>2, last_line => -2 ); say "Content======="; say <$Content>; my $Footer = Tie::FileSection->new( filename => $filename, first_line => -1 ); say "Footer========"; say <$Footer>;
`Tie::FileSection` represent a regular text file specified by the file name, with boundaries to restrict to a specific section of the file. It is possible to use negative boundaries that will be relative to the end of the file. It is designed to works for sequential read accesses.
new
my $fh = Tie::FileSection->new ( filename => $path, first_line => $i, last_line => $end ); my $fh = Tie::FileSection->new ( file => $FH, first_line => $i, last_line => $end ); filename argument is the file path to read from. file argument is the file handle to read from. optional first_line argument is the first line index in the file where the section start, omit this argument to mean from start of the file. optional last_line argument is the last line index in the file where the section end, omit this argument to mean until EOF. optional use_real_line_nr argument when specified with a true value, will make $. to return the original line number, default to relative to the section.
A negative indexes is relative to the end of the file.
`Tie::FileSection`comes with ABSOLUTELY NO WARRANTY. For details, see the license.
Add more tests Support random and write accesses
Nicolas Georges <xlat@cpan.org>
This software is copyright (c) 2017 by Nicolas Georges.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Tie::FileSection, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tie::FileSection
CPAN shell
perl -MCPAN -e shell install Tie::FileSection
For more information on module installation, please visit the detailed CPAN module installation guide.