in reply to Re^2: Question about text::csv_xs
in thread Question about text::csv_xs
Sure, that would very easy. Suppose you wanted to use the third field as hashkey. Then get_parsed_lines would be changed to:
More generally, you may want to use several fields, e.g., fields 0, 2 and 3. In this case, just change the last line in the loop tosub get_parsed_lines { my $file = shift; my $csv = Text::CSV_XS->new(); my %hash; open my $in, '<', $file or die "Read failed: $!\n"; while ( <$in> ) { $csv->parse( $_ ) or warn "Bad data: $_\n", next; my @row = $csv->fields(); $hash{ $row[ 2 ] } = \@row; } close $in or die "Failed to close $file: $!\n"; return \%hash; }
$hash{ join( ',', @row[ 0, 2, 3] ) } = \@row;
the lowliest monk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Question about text::csv_xs
by Thargor (Scribe) on May 04, 2005 at 17:42 UTC |