File-Locate-Iterator
view release on metacpan or search on metacpan
devel/handle.pl view on Meta::CPAN
{ my $eof = eof(FH);
### $eof
}
my $entry = readline(FH);
### $entry
$entry = readline(FH);
### $entry
my @entries = readline(FH);
### @entries
exit 0;
}
{
tie *FH, 'File::Locate::Iterator::TieHandle',
use_mmap => 0,
database_file => 't/samp.locatedb',
;
my $fileno = fileno(FH);
my $pos = tell(FH);
### $fileno
### $pos
my $line = <FH>;
### $line
$line = <FH>;
### $line
my $buf; # = 'x';
my $ret = read(FH,$buf,2,3);
### $ret
### $buf
my $c = getc(FH);
### $c
$c = getc(FH);
### $c
# $line = <FH>;
# ### $line
$pos = tell(FH);
### $pos
my @entries = readline(FH);
### @entries
exit 0;
}
{
open FH, '</etc/passwd' or die;
my $buf;
my $ret = read(FH,$buf,8,3);
### $ret
### $buf
print <FH>;
exit 0;
}
1;
__END__
=for stopwords filename filenames filesystem slocate filehandle arrayref mmap mmaps seekable PerlIO mmapped XSUB coroutining fd Findutils Ryde wildcard charset wordsize wildcards
=head1 NAME
File::Locate::Iterator::TieHandle -- file handle tied to read "locate" database
=head1 SYNOPSIS
use File::Locate::Iterator::TieHandle;
tie *FH, 'File::Locate::Iterator::TieHandle';
while (defined (my $line = <FH>)) {
chomp $line;
print "entry is \"$line\"\n";
}
=head1 DESCRIPTION
C<File::Locate::Iterator::TieHandle> ties a file handle to read entries from
a "locate" database file. Each C<readline()> returns an entry from the
database. C<read()> and C<getc()> can also be used. Writing is not
implemented (as yet).
Each entry has the input record separator C<$/> appended (see L<perlvar>) as
if it was a line from an ordinary file. This can be stripped with C<chomp>
etc in the usual way (see L<perlfunc/chomp>.
=head2 C<seek> and C<tell>
C<tell> gives the current database position in bytes. Normally the only use
for this is to pass to C<seek> to go back to that position again.
C<seek> works as long as the underlying locate database file or handle is
seekable, as per C<rewind()> of L<File::Locate::Iterator/Operations>.
Seeking back to the start of the file is simply an iterator C<rewind>.
Seeking back by a small amount is slow in the current implementation because
the database must be re-read from the start to the target position, but at
least it works.
=head1 SEE ALSO
L<File::Locate::Iterator>, L<perltie>
=head1 HOME PAGE
http://user42.tuxfamily.org/file-locate-iterator/index.html
=head1 COPYRIGHT
Copyright 2011 Kevin Ryde
File-Locate-Iterator is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option) any
later version.
File-Locate-Iterator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
( run in 1.058 second using v1.01-cache-2.11-cpan-df04353d9ac )