Perl array of arrays

 


How to create arrays of arrays (aka two-dimensional arrays) in Perl:

while (<>) {
   @tmp = split;
   push @AoA, [@tmp];
}

or

$AoA[$i] = [ @tmp ];

To display the contents:

   for $aref (@AoA) {
      print %u201C\t [@$aref] \n%u201D;
   }

Or:

   for $i ( 0 .. $#AoA) {
      $aref = $AoA [$i];
      for $j ( 0 .. $#{$aref} ) {
         print $AoA[$i] [$j]
      }
   }

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>