Niyaz
Niyaz

Reputation: 54793

Difference between %something and %{$something}?

Two (almost?) similar questions actually.

  1. What is the difference between %something and %{$something} ?

  2. What is the difference between %{$hashvar{xyz}} and %hashvar{xyz} ?

Upvotes: 0

Views: 122

Answers (1)

Lee Duhem
Lee Duhem

Reputation: 15121

  1. %something means something is a hash variable, and %{$something} means that $something is a scalar variable that contains a reference to a hash

  2. %{$hashvar{xyz}} means $hashvar{xyz} (value associated with key xyz in hash hashvar) is a hash reference

  3. Starting in Perl 5.20, %hashvar{xyz} is a key/value hash slice, will return 'xyz' and $hashvar{xyz}; before that, it is a syntax error.


References:
perldata - Perl data types
perldsc - Perl Data Structures Cookbook

Upvotes: 4

Related Questions