| Text-Filter documentation | view source | Contained in the Text-Filter distribution. |
Text::Filter::Cooked - Cooked reader for input files
use Text::Filter::Cooked;
my $f = Text::Filter::Cooked->new
(input => 'myfile.dat',
comment => "#",
join_lines => "\\");
while ( my $line = $f->readline ) {
printf("%3d\t%s\n", $f->lineno, $line);
}
Text::Filter::Cooked is a generic input reader. It takes care of a number of things that are commonly used when reading data and configuration files.
Text::Filter::Cooked is based on Text::Filter, see Text::Filter.
The constructor is called new() and takes a hash with attributes as its parameter.
The following attributes are recognized and used by the constructor, all others are passed to the base class, Text::Filter.
If true, empty lines encountered in the input are ignored.
If true, leading whitespace encountered in the input is ignored.
If true, trailing whitespace encountered in the input is ignored.
If true, multiple adjacent whitespace are compressed to a single space.
This must be set to a string. Input lines that end with this string (not taking the final line ending into account) are joined with the next line read from the input.
This must be set to a string. Input lines that start with this string are ignored.
This filters the input according to the specified parameters.
use Text::Filter::Cooked;
Text::Filter::Cooked->run
(input => 'myfile.dat',
comment => "#",
join_lines => "\\");
This filters the input and writes all cooked lines together with their line numbers.
use Text::Filter::Cooked;
my $f = Text::Filter::Cooked->new
(input => 'myfile.dat',
comment => "#",
join_lines => "\\");
while ( my $line = $f->readline ) {
printf("%3d\t%s\n", $f->lineno, $line);
}
Johan Vromans (jvromans@squirrel.nl) wrote this module.
This program is Copyright 2007 by Squirrel Consultancy. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of either: a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" which comes with Perl.
This program 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 either the GNU General Public License or the Artistic License for more details.
| Text-Filter documentation | view source | Contained in the Text-Filter distribution. |