That is, of course, if you can live with the idea of changing spaces to dots. Consider:
my @a = ( [qw/. . . # # # . . ./], [qw/. . # # . # # . ./], [qw/. # # . . . # # ./], [qw/# # . . . . . # #/], [qw/# # # # # # # # #/], [qw/# # . . . . . # #/], [qw/# # . . . . . # #/], );
Of course, if you really do need spaces instead of dots in your array entry, you shall have to map the dots back to spaces:
my @a = ( [map{tr/./ /;$_} qw/. . . # # # . . ./], [map{tr/./ /;$_} qw/. . # # . # # . ./], [map{tr/./ /;$_} qw/. # # . . . # # ./], [map{tr/./ /;$_} qw/# # . . . . . # #/], [map{tr/./ /;$_} qw/# # # # # # # # #/], [map{tr/./ /;$_} qw/# # . . . . . # #/], [map{tr/./ /;$_} qw/# # . . . . . # #/], );
Then again, that still looks too stretched out to help you easily comprehend what's in the array. And it's not really much simpler than what you had initially. Better, then, to use a different approach, this time using split.
my @a = ( [split //, q/ ### /], [split //, q/ ## ## /], [split //, q/ ## ## /], [split //, q/## ##/], [split //, q/#########/], [split //, q/## ##/], [split //, q/## ##/], );
As an added bonus, this way we get our spaces back. Short, sharp and sweet.
By the way, get into the habit of adding a trailing comma on the last element of an array. Perl will silently ignore it, and it really comes in handy when you decide to add to or remove the last array element. Basically, you just don't have to worry any more, and it gives all the lines a pleasing symmetry.
In reply to Re: Multidimensional Array
by grinder
in thread Multidimensional Array
by IndirectX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |