in reply to Extract a column of csv

And just to prove it ;o)

use strict; use warnings; use utf8; use Text::CSV; my $io = \*DATA; my $csv = Text::CSV->new ({ binary => 1 }); while (my $row = $csv->getline($io)) { print $row->[1], "\n"; } __DATA__ 33,44,55,"ABC" 234.33,"ABC ""DEFGHIJ"" KLMNOP","asdfasd asdfasdfasdf "
Produces:
44 ABC "DEFGHIJ" KLMNOP

Replies are listed 'Best First'.
Re^2: Extract a column of csv
by Anonymous Monk on Jun 26, 2013 at 13:46 UTC
    Hey

    what if I define it as any sub routine that extracts a particular column so that i can return the extracted array

Re^2: Extract a column of csv
by Anonymous Monk on Jun 27, 2013 at 03:57 UTC
    Hey

    thank you for helping out , I have just one question that here in line

     print $row->[1], "\n";

    our 1 is fixed but i want to extract multiple columns , so I wrote a subroutine

    sub column_segregation { my $o=$_[0]; print "$o \n"; my @array_A2=(); my $csv = Text::CSV->new ({ binary => 1 }); while (my $row = $csv->getline($io)) { push @array_A2, $row->[$o]; } return (@array_A2); }

    but here $o is changing but it constantly returns the same array , which is at location 2. can you please tell me what is wrong in my code