|
NAMEArray::LineReader - Access lines of a file via an arraySYNOPSISuse Array::LineReader; my @lines; # Get the content of every line as an element of @lines: tie @lines, 'Array::LineReader', 'filename'; print scalar(@lines); # number of lines in the file print $lines[0]; # content of the first line print $lines[-1]; # content of the last line ... # Get the offset and content of every line as array reference via the elements of @lines: tie @lines, 'Array::LineReader', 'filename', result=>[]; print scalar(@lines); # number of lines in the file print $lines[5]->[0],":",$lines[5]->[1]; # offset and content of the 5th line print $lines[-1]->[0],":",$lines[-1]->[1]; # offset and content of the last line ... # Get the offset and content of every line as hash reference via the elements of @lines: tie @lines, 'Array::LineReader', 'filename', result=>{}; print scalar(@lines); # number of lines in the file print $lines[4]->{OFFSET},":",$lines[4]->{CONTENT}; # offset and content of the 4th line print $lines[-1]->{OFFSET},":",$lines[-1]->{CONTENT}; # offset and content of the last line ... VERSION and VOLATILITY$Revision: 1.1 $ $Date: 2004/06/10 18:17:23 $ DESCRIPTIONArray::LineReader gives you the possibility to access lines of some file by the elements of an array. This modul inherites methods from "Tie::Array" (see Tie::Array). You save a lot of memory, because the file's content is read only on demand, i.e. in the case you access an element of the array. The offset and length of all the lines is hold in memory as long as you tie your array.The underlying file is opened for reading in binary mode. (Yes, there are some OSs, that make a difference in interpreting the "EOL"-sequence, i.e. "End-Of-Line" and the "EOF"-character, i.e. "End-Of-File" what is the character "\x1A"). The bytes read are neigther translated nor suppressed. Lines are build up to and including the "EOL"-sequence. The "EOL"-sequence is assumed to be "\x0D\x0A" or "\x0A\x0D" or "\x0D" or "\x0A". The file is not closed until you "untie" the array. It's up to you to define the kind of access: Access content by elementtie @lines, 'Array::LineReader', 'filename'; You get the content of every line of the file by the elements of the array @lines: print "@lines"; Access offset and content by array referencestie @lines, 'Array::LineReader', 'filename', result=>[]; You get offset and content of every line of the file via the elements of the array @lines: foreach (@lines){ print $_->[0],":"; # offset print $_->[1]; # content } Access offset and content by hash referencestie @lines, 'Array::LineReader', 'filename', result=>{}; You get offset and content of every line of the file via the elements of the array @lines: foreach (@lines){ print $_->{OFFSET},":"; # offset print $_->{CONTENT}; # content } METHODSTIEARRAY
FETCHSIZE
FETCH
DESTROY
EXISTS
EXPORTNone by default.SEE ALSOArray::FileReader, Tie::Array, Tie::FileHISTORY* $Log: LineReader.pm,v $ * Revision 1.1 2004/06/10 15:07:37 Bjoern_Holsten * First stable (as seems) version * AUTHORBjoern Holsten <bholsten + At + cpan + DoT + org>COPYRIGHT AND LICENSECopyright (C) 2004 by Bjoern HolstenThis library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.0 or, at your option, any later version of Perl 5 you may have available.
Visit the GSP FreeBSD Man Page Interface. |