in reply to issue with column extraction in perl
You do not have $io in the sub you need to pass this to it or open the file within that sub.
use strict; use warnings; use Text::CSV; open my $fh, "<:encoding(utf8)", "test.csv" or die "test.csv: $!"; my @rows = column_segregation( $fh, 2 ); print "$_\n" for @rows; close $fh; sub column_segregation { my ( $io, $o ) = @_; my $csv = Text::CSV->new ({ binary => 1 }); my @array_A2; while (my $row = $csv->getline($io)) { push @array_A2, $row->[$o]; } return (@array_A2); }
Input 1,2,3,4 5,6,7,8 a,b,c,d Output 3 7 c
|
|---|