On Oct 18, 11:44 am, [EMAIL PROTECTED] (Pedro Soto) 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?
> Thanks in advance,
> P
>
> #! usr/local/bin/perl
> use warnings;
> use strict;
> my @AoA= ();
> open(IN,"genotypes_piece") || die "I can not open file\n";
> my @temp =();
> while (defined (my $line = <IN>)) {
> @temp = split/\s+/,$line;
> push(@AoA, [EMAIL PROTECTED]);
>
> }
>
> for (my $x = 11; $x <=$#temp; $x++) {
>      for (my $y = 1; $y <= $#AoA ; $y ++) {
>      print "At X=$x, Y=$y is", $AoA[$y][$x], "\n";
>
>
>
> }
> }

To dereference a reference, you enclose the reference in { } and
prepend the appropriate sigil ($ for scalar, @ for array, % for hash)

for my $heading (@{$AoA[0]}) {
  print "$heading\t";
}
print "\n";

or more simply
print join("\t", @{$AoA[0]}), "\n";

Read up on references in:
perldoc perlreftut
perldoc perllol

Paul Lalli


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


Reply via email to