title: How can I print a two-dimensional array in Perl?
body: <p>I have a two-dimensional array. When I print/dump this I get the following</p>
  <p>My two-dimensional array:</p>
  <pre><code>push (@matrix, \@a1Comparea2);
  push (@matrix, \@a3Comparea4);
  </code></pre>
  <p>a1Comparea2 should be the first row of the array. a3Comparea4 should be the second row of the array.</p>
  <pre><code>$VAR1 = [
            [
              '1 6',
              '2 7',
              '3 8',
              '4 9',
              '5 10'
            ],
            $VAR1-&gt;[0],
            $VAR1-&gt;[0],
            $VAR1-&gt;[0],
            $VAR1-&gt;[0],
            [
              '7 12',
              '8 13',
              '9 14',
              '10 15',
              '11 16'
            ],
            $VAR1-&gt;[5],
            $VAR1-&gt;[5],
            $VAR1-&gt;[5],
            $VAR1-&gt;[5]
          ];
  </code></pre>
  <p>When I try to print this with the following code:</p>
  <pre><code>for (my $j= 0; $j &lt; $rows; $j++)
  {
      for (my $k= 0; $k &lt; @a1; $k++)
      {
          print &quot;Row:$j Col:$k = $matrix[$j][$k]\n&quot;;
      }
  }
  </code></pre>
  <p>I get the following output:</p>
  <pre class="lang-none prettyprint-override"><code>Row:0 Col:0 = 1 6
  Row:0 Col:1 = 2 7
  Row:0 Col:2 = 3 8
  Row:0 Col:3 = 4 9
  Row:0 Col:4 = 5 10
  Row:1 Col:0 = 1 6
  Row:1 Col:1 = 2 7
  Row:1 Col:2 = 3 8
  Row:1 Col:3 = 4 9
  Row:1 Col:4 = 5 10
  </code></pre>
  <p>As you can see, the data is duplicated.</p>