in reply to Re^3: Having trouble reading in a hash from a referenced array
in thread Having trouble reading in a hash from a referenced array

Quite right you are.

But I feel that making the arrow optional between two subscripts is confusing if Perl still makes a distinction between a reference and the data structure it refers to. I guess the rule is simple: PDS (Perl Data Structure=hash,array) can not contain arrays but refs or scalars. So drop the arrow notation. Hmmmm that might be confusing for a new-comer as it may suggest that arrays (not arrayref) is allowed inside a PDS.

That's a general Perl comment, not about what you wrote.

  • Comment on Re^4: Having trouble reading in a hash from a referenced array

Replies are listed 'Best First'.
Re^5: Having trouble reading in a hash from a referenced array
by jo37 (Curate) on Dec 19, 2020 at 14:09 UTC

    Maybe the intention is to allow $a[1][2][3] instead of the clumsy $a[1]->[2]->[3].

    Greetings,
    -jo

    $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$
Re^5: Having trouble reading in a hash from a referenced array
by LanX (Saint) on Dec 19, 2020 at 01:04 UTC
    I think of an @array as just syntactic sugar for an $a_ref = \@array.

    They are not two different data types, just two sides of the same coin.

    Without @sigil and %sigil many context mechanics wouldn't work.

    Edit

    Concerning repeated arrows ...

    Perl is very special among other scripting languages in requiring explicit dereferencing. (this might be a C thing, I'm not sure)

    How would you explain to someone coming from JS, Python or Ruby that he not only needs one -> but a bunch full for every level?

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

      > They are not two different data types,

      OK, before someone starts complaining:

      Yes Perl has an internal type for scalars holding references, so $a_ref would be of that type. But that's not what I meant.

      Every @array has already a ref-address for the internal memory location, even before you try assigning it explicitly to a $scalar

      DB<8> use Devel::Peek DB<9> @x=(1) DB<10> Dump @x SV = PVAV(0x31c26e0) at 0x31dbe08 <---- REFCNT = 1 FLAGS = () ARRAY = 0x31ff138 FILL = 0 MAX = 3 ARYLEN = 0x0 FLAGS = (REAL) Elt No. 0 SV = IV(0x31dba20) at 0x31dba30 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1 DB<11> p \@x ARRAY(0x31dbe08) <---- DB<12>

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