CSV-Reader
view release on metacpan or search on metacpan
- ```field_aliases```: hashref of case insensitive alias (in file) => real name (as expected in code) pairs.
- ```field_normalizer```: callback that receives a field name by reference to normalize (e.g. make lowercase).
- ```include_fields```: arrayref of field names to include. If given, then all other field names are excluded.
- ```delimiter```: string, default ','
- ```enclosure```: string, default '"'
- ```escape```: string, default backslash
- ```mutators```: hashref of field name => callback($value_ref, $row_ref) pairs.
Note: the option ```field_aliases``` is processed after the option ```field_normalizer``` if given.
Note: the callbacks given with the ```mutators``` option are called in their key order (which is an unpredictable order unless they're tied with Tie::IxHash).
Public object methods
---------------------
### fieldNames()
Returns the field names as an array.
### current()
lib/CSV/Reader.pm view on Meta::CPAN
- field_aliases: hashref of case insensitive alias (in file) => real name (as expected in code) pairs.
- field_normalizer: callback that receives a field name by reference to normalize (e.g. make lowercase).
- include_fields: arrayref of field names to include. If given, then all other field names are excluded.
- delimiter: string, default ','
- enclosure: string, default '"'
- escape: string, default backslash
- mutators: hashref of field name => callback($value_ref, $row_ref) pairs.
Note: the option field_aliases is processed after the option field_normalizer if given.
Note: the callbacks given with the mutators option are called in their key order (which is an unpredictable order unless they're tied with Tie::IxHash).
=cut
sub new {
my $proto = shift;
my $file = shift;
my %options = @_;
my $self = {
'h' => undef, # File handle.
'own_h' => undef, # Does this class own the file handle.
lib/CSV/Reader.pm view on Meta::CPAN
'binary' => 1,
'blank_is_undef' => 1,
'empty_is_undef' => 1,
'sep_char' => $self->{'delimiter'},
'escape_char' => $self->{'escape'},
'quote_char' => $self->{'enclosure'},
%text_csv_options, # undocumented experimental feature; consider overriding _new_text_csv_object() instead.
}) || die('Method _new_text_csv_object() did not return a Text::CSV object as expected');
# Emulate the original Text::CSV error message format but without the LF and with the caller script/module.
if (0 && $text_csv->can('callbacks')) { # exists since Text::CSV_XS version 1.06
$text_csv->callbacks(
'error' => sub {
my ($err, $msg, $pos, $recno, $fldno) = @_; # This is dumb because the object itself is not given.
if ($err eq '2012') { # EOF
return;
}
#CSV_XS ERROR: 2021 - EIQ - NL char inside quotes, binary off @ rec 10 pos 51 field 6
#die 'error args: ' . Data::Dumper::Dumper(\@_);
local $Carp::CarpInternal{'Text::CSV'} = 1;
local $Carp::CarpInternal{'Text::CSV_PP'} = 1;
local $Carp::CarpInternal{'Text::CSV_XS'} = 1;
( run in 0.591 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )