Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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 (Canon) 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 (Priest) 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
Corion is mildly surprised as some different toy projects coagulate into a useful application. I've been toying with writing a Meetup wrapper and also have been toying with synchronizing events between (CalDAV) calendars, and now that means I can ...
[Corion]: ... easily* synchronize my personal calendar with Meetup and import stuff from Meetup there
[Corion]: * Code not yet written, some restrictions may apply

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (13)
As of 2017-02-23 09:37 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (343 votes). Check out past polls.