Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Read the csv file to a hash....

by Tux (Canon)
on Jul 09, 2007 at 11:49 UTC ( [id://625592]=note: print w/replies, xml ) Need Help??


in reply to Read the csv file to a hash....

Not one of the answers addresses the problem with using <> for reading CSV lines that might have embedden newlines

use strict; use warnings; use Text::CSV_XS; my %hash; my $csv = Text::CSV_XS->new ({binary => 1, eol => "\n"}); open my $io, "<", "file.csv" or die "file.csv: $!"; my @fld = @{$csv->getline ($io)}; while (my $row = $csv->getline ($io)) { push @{$hash{$fld[$_]}}, $row->[$_] for 0 .. $#fld; } close $io;

Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://625592]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-20 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found