1

I really really don't undertand perl hash. I have been reading perl doc but not able to completely get perl reference.

For a prime example, can you please tell me the difference between below?

 @{$table}{$item}
 @{$table{$item}}
 %{$table}{$item}
 %{$table{$item}}

Or is there some general rule that I am missing from not able to decipher these?

Please point me to right direction. I have been reading perldoc.perl.org..

hanabbs
  • 149
  • 6
  • https://perldoc.perl.org/perllol and https://perldoc.perl.org/perldsc are a good place to start – tobyink Jan 10 '21 at 01:18
  • For references see [perlreftut](https://perldoc.perl.org/perlreftut) and [perlref](https://perldoc.perl.org/perlref). Also see [perldata](https://perldoc.perl.org/perldata) – zdim Jan 10 '21 at 01:38
  • thanks guys, I went through them lightly. If there is an answer in these, I will go through them more throughly. thanks – hanabbs Jan 10 '21 at 01:43

1 Answers1

5

Just replace the reference-producing block ({ ... }) with an identifier to get a better sense of what you have.

  • @{$table}{$item}
    • Akin to @name{$item}
    • Array slice of the array referenced by $table
    • Can also be written as $table->@{$item}
    • There's no point to using a slice when there's only one item returned by the index expression. Should be ${$table}{$item} or $table->{$item}.
  • @{$table{$item}}
    • Akin to @name
    • Array referenced by $table{$item}
    • Can also be written as $table{$item}->@*
  • %{$table}{$item}
    • Akin to %name{$item}
    • Key-value hash slice of the hash referenced by $table
    • Can also be written as $table->%{$item}
  • %{$table{$item}}
    • Akin to %name
    • Hash referenced by $table{$item}
    • Can also be written as $table{$item}->%*

See

ikegami
  • 367,544
  • 15
  • 269
  • 518