subcall( $M[0] );

Assuming that  @M is initialized as shown in Re^2: Arrays in arrays, how to access them, you get, in this instance, an array reference passed to the  subcall() function because that's what element 0 of the  @M array is.

subcall( \@{M[0]} )

In this instance (assuming it's fixed to
    subcall( \@{$M[0]} )
by adding the missing  $ sigil), you have, working from the inside out:

In this instance, you're simply wrapping the access to  $M[0] in a redundant pair of complementary operations — and maybe in this case the compiler would even be smart enough to optimize away the redundancy! It's as if you had asked "Why do the two function calls
    func($x);
and
    func($x + 1729 - 137 - 1729 + 137);
both pass the same value to the function?"

Ah, but if I use
subcall ( @{\@{$M[0]}} )
...

If you use
    subcall ( @{\@{$M[0]}} )
you extend the process of the second instance above to de-reference the array reference created (redundantly) by  \@{$M[0]} and pass an array (in the example, the  @a1 array) to the  subcall() function, which is apparently what it takes to make that function happy.

>perl -wMstrict -le "my @a1 = qw(a b c); my @a2 = qw(p q r); my @a3 = qw(x y z); my @M = (\@a1, \@a2, \@a3); ;; print $M[0]; print \@{$M[0]}; ;; print 'array references are the same' if $M[0] == \@{$M[0]}; ;; print qq{-@{\@{$M[0]}}- -@{$M[0]}-}; " ARRAY(0x43281c) ARRAY(0x43281c) array references are the same -a b c- -a b c-

(Also see perlreftut.)


In reply to Re^4: Arrays in arrays, how to access them by AnomalousMonk
in thread Arrays in arrays, how to access them by viored

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.