in reply to Read the csv file to a hash....
- Milleruse Text::CSV_XS; use strict; use warnings; my $csvfile = shift or die "No filename specified"; my $csv = Text::CSV_XS->new(); my @columns; open(FILE, $csvfile) or die "Can't open $csvfile: $!"; while (<FILE>) { $csv->parse($_) or die "parse() failed: " . $csv->error_input(); my @data = $csv->fields(); for my $i (0..$#data) { push @{$columns[$i]}, $data[$i]; } } close(FILE); my %hash = map {shift @$_ => $_} @columns; use Data::Dumper; print Dumper(\%hash);
|
---|