Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello

I have a csv file and i am seprating out its column , the function defined for it is

sub column_segregation_Spec_values { my ($file,$col) = @_; use Text::CSV; my @array_A2 = (); open my $io,'<',$file or die "$!"; my $csv = Text::CSV->new ({ binary => 1 }); while (my $row = $csv->getline($io)) { push @array_A2, $row->[$col]; } close $io; return (@array_A2); }

Now this function will return seperated columns as array . Now since the number of columns are unknown , I wish to put them in double dimension array , as one column will occupy one row and so on , how can i do it

please don't suggest to use split , because I can't because there can be a user given comma . thanks in advance

Replies are listed 'Best First'.
Re: taking csv and seprating unknown number of columns
by Tux (Canon) on Jul 23, 2013 at 13:42 UTC
    my $arrayref = $csv->getline_all ($io);

    Enjoy, Have FUN! H.Merijn
Re: taking csv and seprating unknown number of columns
by hdb (Monsignor) on Jul 23, 2013 at 14:26 UTC
Re: taking csv and seprating unknown number of columns
by Anonymous Monk on Jul 23, 2013 at 13:41 UTC
    push @foo, $row; ## DOUBLE DIMENSIONAL
Re: taking csv and seprating unknown number of columns
by Laurent_R (Canon) on Jul 23, 2013 at 22:26 UTC

    Don't use:

    use Text::CSV;

    in a subroutine. It might be called several (or many) times uselessly. Usually, use statements should be at file top level.

      It might be called several (or many) times uselessly.

      Perhaps you'd like to read perldoc -f use and revise your answer

        You are right, 'use' is perfomed at compile time, and I know it and knew it, and I don't know why I wrote that. I must have been sleeping. Still, it is better practice in my view to have all the use statements at the top of the file, that's what I really meant to say, but I got carried away somehow.