Dave's Brain

Browse - Programming Tips - How do I declare, initialize and use 2D arrays in perl?

Date: 2012mar24
Language: perl

Q.  How do I declare, initialize and use 2D arrays in perl?

A.  Unlike compiled languages like C++ or Java
you don't declare variable to be a 2D array.

In Perl you make an array of array:

my @AoA = ( [ "fred", "barney" ], [ "george", "jane", "elroy" ], [ "homer", "marge", "bart" ], );
Notice there are round brackets on the outside and square brkacets on the inside. More info http://perldoc.perl.org/perldsc.html#ARRAYS-OF-ARRAYS

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.