use Text::CSV;
my $csv = Text::CSV->new ({
binary => 1, # allow binary data
auto_diag => 1, # allow automatic warnings and errors
sep_char => ",", # , is the default, ; is also use quite often
});
open my $fh, "<", "file.csv" or die "file.csv: $!";
while (my $row = $csv->getline ($fh)) {
say "The second field is ", $row->[1];
}
If you want a parser WITHIN a parser, just create a second parser
use Text::CSV;
my $csv = Text::CSV->new ({
binary => 1,
auto_diag => 1,
sep_char => ",",
});
my $parser = Text::CSV->new ({
binary => 1,
auto_diag => 1,
sep_char => ";", # sep is ;
});
open my $fh, "<", "file.csv" or die "file.csv: $!";
while (my $row = $csv->getline ($fh)) {
say "The second field is ", $row->[1];
foreach my $f (@$row) {
$parser->parse ($f) or next;
my @subfields = $parse->fields;
}
}
Enjoy, Have FUN! H.Merijn
|