Gack, that's an awful lot of punctuation to get right. I would lean towards using Perl's quoteword facility, it would make things much easier to read.

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.


print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'

In reply to Re: Multidimensional Array by grinder
in thread Multidimensional Array by IndirectX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.