On 10/18/07, Pedro Soto <[EMAIL PROTECTED]> wrote:
> Dear all,
> I am trying to make a matrix out of a file (row-columns) using perl. In
> particular I would like to print the first row of an array of arrays which
> contains the headings of the file.
> I tried to do it but I can't print it. If used $AoA[0], I get the reference
> to the array.How can I deference it?
snip

An AoA stores the row (or y values) in the first offset and the column
(or x values) in the second offset, so you should access it like
$AoA[$y][$x], or preferably with the iterator version of the for loop:

#! usr/local/bin/perl

use warnings;
use strict;

my @AoA;

open my $in, '<', "genotypes_piece"
    or die "I can not open file:$!\n";

push @AoA, [ split ] while <$in>;

my $y = 0;
for my $row (@AoA) {
        my $x = 0;
        for my $col (@$row) {
                print "At X=$x, Y=$y is $col which should also be
$AoA[$y][$x]\n";
                $x++;
        }
        $y++;
}

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to