Return to Snippet

Revision: 42395
at March 4, 2011 07:31 by alfirth


Initial Code
use Data::Dumper;
my $csv = Text::CSV->new ( { binary => 1 } )  # should set binary attribute.
	or die "Cannot use CSV: ".Text::CSV->error_diag ();
open my $fh, "<:encoding(utf8)", "$infile" or die "$infile $!";

$csv->column_names ($csv->getline ($fh));

while ( my $hr = $csv->getline_hr( $fh ) ) {
	$hash{ $hr->{fieldA} }= $hr->{valueA};
}

$csv->eof or $csv->error_diag();
close $fh;

print Dumper(%hash)

Initial URL


Initial Description


Initial Title
Text::CSV by hashref

Initial Tags
csv

Initial Language
Perl