Some nested data structure

Q

Assume that $ref refers to a scalar, an array, a hash or to some nested data structure. Explain the following statements:

✍: Guest

A
  • $$ref; # returns the scalar pointed by $ref.
  • $$ref[0]; # returns the first element of the array pointed by $ref.
  • $ref->[0]; # returns the first element of the array pointed by $ref.
  • @$ref; # returns the contents of the array, (or number of elements of the array in scalar context) pointed by $ref.
  • $&$ref; # returns the last index in the array pointed by $ref.
  • $ref->[0][5]; # returns the sixth element in the first row of the array pointed by $ref.
  • @{$ref->{key}} # returns the contents of the array stored as the value of the key "key" in the associated array pointed by $ref.

2007-11-21, 5727👍, 0💬