Rule 1: thou shallt not read the lines yourself! When you read with the diamond operator, (embedded) line separation gets lost. So instead of:
my $csv = Text::CSV_XS->new ({ quote_char => '"', sep_char => ":", binary => 1, }); 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]; }
Use:
my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1, allow_loose_quotes => 1, }); my @columns; open my $fh, "<", $file or die "$file: $!"; while (my $row = $csv->getline ($fh)) { for (@$row) { my ($key, $value) = split m/"?:"?/, $_, 2; # ... }
In reply to Re: Issue parsing CSV into hashes?
by Tux
in thread Issue parsing CSV into hashes?
by tx2010
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |