NAME
Tie::FileSection - restrict files sequential access using array like boundaries
VERSION
version 0.171950
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
will be relative to the end of the file. It is designed to works
for
sequential
read
accesses.
NAME
Tie::FileSection - restrict files sequential access using array like boundaries
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.
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.
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.