The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Tie::FileSection - restrict files sequential access using array like boundaries

VERSION

version 0.171852

NAME Tie::FileSection - restrict files sequential access using array like boundaries

SYNOPSIS 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>;

DESCRIPTION `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.

METHOD

new - Create a file section and return it as a file handle.

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. 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. last_line argument is the last line index in the file where the section end, omit this argument to mean until EOF.

A negative indexes is relative to the end of the file.

AUTHOR Nicolas Georges From an idea of Emmanuel Dupuis.

LICENSE Perl5 Artistic license.

WARRANTY `Tie::FileSection`comes with ABSOLUTELY NO WARRANTY. For details, see the license.

TODO Add more tests Support random and write accesses

AUTHOR

Nicolas Georges <xlat@cpan.org>

COPYRIGHT AND LICENSE

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.