Parse-CSV-Colnames
view release on metacpan or search on metacpan
lib/Parse/CSV/Colnames.pm view on Meta::CPAN
my $objects = Parse::CSV::Colnames->new(
handle => $io_handle,
sep_char => ';',
fields => 'auto',
# select only rows where column name fieldname is "value"
filter => sub { if($_->{fieldname} eq "value")
{$_} else
{undef}
}
);
# get column names
my @fn=$objects->colnames
# you want lower case field names
@fn=map {lc} @fn;
# you want field names without blanks
@fn=map { s/\s+//g} @fn;
# set column names
$objects->colnames(@fn);
while ( my $object = $objects->fetch ) {
$object->do_something;
}
=head1 DESCRIPTION
This module is only an extension of L<Parse::CSV>
For a detailed description of all methods see L<Parse::CSV>
For a detailed description of the underlying csv-parser see L<Text::CSV_XS>
=cut
use 5.005;
use strict;
use Carp ();
#use IO::File ();
#use Text::CSV_XS ();
#use Params::Util qw{ _STRING _ARRAY _HASH0 _CODELIKE _HANDLE };
use Parse::CSV;
our @ISA=("Parse::CSV");
use vars qw{$VERSION};
BEGIN {
$VERSION = '0.07';
}
=pod
=head1 Fixed METHODS
These methods have not work in the parent module L<Parse::CSV> yet, because Adam Kennedy is very busy.
=head2 combine
$status = $csv->combine(@columns);
The C<combine> method is passed through
to the underlying L<Text::CSV_XS> object. See example 3.
It sets the fields and constructs the corresponding csv string from the arguments. You can read this array with the C<fields> method.
=cut
sub combine {
shift->{csv_xs}->combine(@_);
}
=pod
=head2 string (deprecated)
$line = $csv->string;
The C<string> method is passed through
to the underlying L<Text::CSV_XS> object. See example 3 and example 4.
It returns the parsed string or the corresponding combine-setting.
=cut
#sub string {
# shift->{csv_xs}->string(@_);
#}
=pod
=head2 print
$status = $csv->print($io, $colref);
The C<print> method is passed through
to the underlying L<Text::CSV_XS> object. See example 1.
It prints the string of the corresponding @$colref directly to an IO handle.
=cut
sub print {
shift->{csv_xs}->print(@_);
}
=pod
=head1 Added METHODS
=head2 fields (deprecated)
@fields = $csv->fields;
The C<fields> method is passed through
( run in 2.200 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )