Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: issue with column extraction in perl

by rnewsham (Curate)
on Jun 27, 2013 at 07:02 UTC ( [id://1040930]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-19 20:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found