in reply to Re: Parsing CSV into a hash
in thread Parsing CSV into a hash
The significant changes from your version are:use Text::xSV; my $parser = Text::xSV->new( filename=>$datafile, sep=>"\t" ); $parser->read_header; my %data; while (my $row_ref = $parser->get_row) { $data{ $row_ref->[1] } = $parser->extract_hash; }
UPDATE: A closer reading of the original question shows that the format differs from the obvious. The first row has an extra # in it that is not lined up with the other fields and needs to be discarded. Here is a solution to that variant:
use Text::xSV; my $parser = Text::xSV->new( filename=>$datafile, sep=>"\t" ); my @headers = $parser->get_row; shift @headers; # Get rid of the unwanted # $parser->bind_fields(@headers); my %data; while (my $row_ref = $parser->get_row) { $data{ $row_ref->[1] } = $parser->extract_hash; }
|
|---|