Search code examples
arraysperlpragmastrict

Perl: How to predeclare a two-dimensional array?


After introducing:

use strict;

My 2-dimensional array do not work any more, and I find no description and no example in the documentation how to predeclare them. So, what have I to do?


Solution

  • You declare it in just the same way you would a 1D array:

    use strict;
    use warnings;
    
    my @AoA =  ( ['a', 'b'], ['foo', 'bar'] );
    
    print Dumper \@AoA;
    
    $VAR1 = [
              [
                'a',
                'b'
              ],
              [
                'foo',
                'bar'
              ]
            ];