NAME |
Synopsis |
Description |
Distributions |
Constructor and initialization |
Method: fetchrow_hashref() |
Example code |
Required Modules |
Similar Modules |
Changes |
Author |
Copyright |
NAME
Synopsisuse Text::CSV_PP::Iterator; my($parser) = Text::CSV_PP::Iterator -> new
({
column_names => [qw/One Two Three Four Five/],
file_name => 'no.heading.in.file.csv',
});
my($hashref); while ($hashref = $parser -> fetchrow_hashref() )
{
print map{"$_ => $$hashref{$_}. "} sort keys %$hashref;
print "\n";
}
Description
It is a convenient wrapper around Text::CSV_PP. Points of interest: o Text::CSV_PP::Iterator reads the file for you, using Iterator::IO.
Warning: Iterator::IO V 0.02 has 3 bugs in it, where it does not
call throw() properly. I've reported this via http://rt.cpan.org
o All of Text::CSV_PP's new() parameters are supported by the fact
that Text::CSV_PP::Iterator subclasses Text::CSV_PP
o All data is returned as a hashref just like DBI's fetchrow_hashref(),
using Text::CSV_PP::Iterator's only method, fetchrow_hashref()
o The module reads the column headers from the first record in the file, or ...
o The column headers can be passed in to new() if the file has none
o Non-existent file errors throw the exception Iterator::X::IO_Error,
which stringifies to a nice error message if you don't catch it
o EOF returns undef to allow this neat construct:
while ($hashref = $parser -> fetchrow_hashref() ){...}
o Dependencies:
- Iterator::IO
- Text::CSV_PP
o Example code: t/test.t demonstrates:
- How to call fetchrow_hashref in isolation and in a loop
- How to call fetchrow_hashref in eval{...} and catch exceptions
DistributionsThis module is available both as a Unix-style distro (*.tgz) and an ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file. See http://savage.net.au/Perl-modules.html for details. See http://savage.net.au/Perl-modules/html/installing-a-module.html for help on unpacking and installing each type of distro. Constructor and initializationnew(...) returns a This is the class's contructor. Usage: Text::CSV_PP::Iterator -> new({...}). This method takes a hashref of parameters. Only the file_name parameter is mandatory. For each parameter you wish to use, call new as new({param_1 => value_1, ...}).
Method: fetchrow_hashref()Returns an hashref ref of column data from the next record in the input file. Example codeSee the file t/test.t in the distro. Required ModulesSimilar ModulesThere are quite a few modules on CPAN which offer ways of processing CSV (and similar) files:
ChangesSee Changes.txt. Author
Home page: http://savage.net.au/index.html CopyrightAustralian copyright © 2007, Ron Savage. All rights reserved. All Programs of mine are 'OSI Certified Open Source Software'; you can redistribute them and/or modify them under the terms of The Artistic License, a copy of which is available at: http://www.opensource.org/licenses/index.html |
| Top of page |