This should be a proper thread, I considered that it's moved into one.

> I have no problem using or understanding that noisier indirection syntax, but there must be an explanation beyond my current understanding of the arrow operator. Thoughts please?

Short answer

Symmetry!

$arr_ref->[@slice] doesn't "work" because the analog $arr[@slice] also doesn't do what you mean.

NB: @arr[@slice] is different.

Long answer

Perl is pretty consistent that $ means scalar and @ means a list. The whole context rules depend on it. Something like $ref->[@slice] is as misleading as $arr[@slice] because a scalar has to be returned. (What's happening here is that the scalar value of @slice is calculated instead of a list)

For a slice the correct syntax is @arr[@slice]

Compare the analogy

DB<12> @a = "a".."z"; $ar = \@a DB<13> p $ar->[1], $a[1] bb DB<14> @slice = 1..3 DB<15> p $ar->[@slice], $a[@slice] dd DB<16> p $ar->@[@slice], @a[@slice] bcdbcd DB<17> p @$ar[@slice], @a[@slice] bcdbcd

The deref syntax in line 16 is newer and was introduced to avoid @{...} constructs like in line 17 (In this case the brackets are optional)

What you are suggesting would break the symmetry and cause confusion and bugs.

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

Updates

Added short answer


In reply to Re^3: Hash syntax (slice from arrayref) by LanX
in thread Hash syntax by mvanle

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.