Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Extract a column of csv

by Tux (Abbot)
on Jun 26, 2013 at 05:57 UTC ( #1040706=note: print w/replies, xml ) Need Help??

in reply to Extract a column of csv

# get the 4th column my @column = map { $_->[3] } @{$csv->getline_all ($fh)};

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^2: Extract a column of csv
by Anonymous Monk on Jun 26, 2013 at 13:34 UTC
    hey i did this as per your advice
    my $in_file = 'C:\Documents and Settings\x0199665\My Documents\coll\t +gb.csv'; # open my $fh, '<', $in_file or die "could not open $in_file: $!\n"; my @column = map { $_->[4] } @{$csv->getline_all ($fh)};
    but it gives an error "can't call getline on an unidentified value

      Please start reading the documentation for Text::CSV_XS or Text::CSV. To me this error indicates that you forgot to initiate the $csv object (or that you are using a very old Text::CSV):

      use Text::CSV_XS; # or use Text::CSV; my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1 });

      update: can I see both the script and the data? Not much has changed for getline_all () in Text::CSV_XS since Dec 2010, when it was introduced

      Enjoy, Have FUN! H.Merijn

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1040706]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2018-04-19 21:53 GMT
Find Nodes?
    Voting Booth?