Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Columns in double dimension array

by torres09 (Acolyte)
on Jul 17, 2013 at 08:21 UTC ( #1044753=perlquestion: print w/replies, xml ) Need Help??
torres09 has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks

I am taking columns from a csv file , now I don't have the exact number of columns so I wish to use Double dimension array

so here is what I am doing

sub column_segregation { 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); }

so this routine will return an array , now i want each column should go to each corresponding column in Double dimension array. i.e. column 1 should go to column of 1 DD array and so on .

So I have never worked with DD array so how to put it in the DD array column is what I need help with <\n>

Replies are listed 'Best First'.
Re: Columns in double dimension array
by kcott (Chancellor) on Jul 17, 2013 at 08:42 UTC

    G'day torres09,

    You asked about this less than 48 hours ago: indefinite number of columns

    You were provided with code for doing this and links to documentation explaining about this. How about you go back and read what's already been provided.

    If there was something you didn't understand, either in the code examples posted or the documentation linked to, then ask a specific question about that issue.

    -- Ken

Re: Columns in double dimension array
by Skeeve (Vicar) on Jul 17, 2013 at 08:46 UTC

    I think, I don't understand the problem completely.

     $csv->getline($io) already returns a ref to an array where, each entry "n" is the cell of column "n+1".

    So this should already give you the correct array:

    while (my $row = $csv->getline($io)) { push @DD, $row; }

    $DD[$r][$c] should give you the entry in row "r+1" and column "c+1".

Re: Columns in double dimension array
by Anonymous Monk on Jul 17, 2013 at 08:49 UTC
Re: Columns in double dimension array
by mtmcc (Hermit) on Jul 17, 2013 at 08:57 UTC
    The documentation for array of arrays is here.

    Also, you could google it.

    I hope that helps.


Re: Columns in double dimension array
by BillKSmith (Vicar) on Jul 17, 2013 at 13:37 UTC
    Strictly speaking, perl does not support double dimension arrays. It simulates them very well with arrays of references! The implication of this is that you cannot ignore the discussion of references in the doucmentation you have alread been given.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1044753]
Approved by Corion
[Discipulus]: good morning nuns and monks!

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2018-06-21 07:09 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.