title: Iterating through 2 matrices in perl
body: <p>I am trying to write a program that sums two matrices (implemented as a double array) in perl.</p>
  
  <p>I'm sure there's some function that can do it for me, but this is for a homework assignment, so I need to do it myself.</p>
  
  <p>My problem, I'm sure, is in the syntax.  Can you explain what I am doing wrong?</p>
  
  <pre><code>sub matrix_add {
    my @matrix1 = $_[0];
    my @matrix2 = $_[1];
    for my $x (0 .. $#matrix1){
      my @line1 = @matrix1[$x];
      my @line2 = @matrix2[$x];
      for my $y (0.. $#line1){
          @line1[$y] += @line2[$y];
      }
    }
    return @matrix1
  }
  </code></pre>
  
  <p>I am not getting any errors, but when I print out the array, I'm printing out what I think are references:</p>
  
  <pre><code> ARRAY(0x508a24)ARRAY(0x508b44)
  </code></pre>
  
  <p>Additional info:</p>
  
  <p>I'm declaring the matrices like such:</p>
  
  <pre><code>my @matrix = ( 
   [0, 1], 
   [2, 3] 
   ); 
  </code></pre>
  
  <p>and printing them out them using a double for-each.</p>