Perl Language Lists Hash as list


Example

In list context hash is flattened.

my @bar =  ( %hash, %hash );

The array @bar is initialized by list of two %hash hashes

  • both %hash are flattened
  • new list is created from flattened items
  • @bar array is initialized by that list

It is guaranteed that key-value pairs goes together. Keys are always even indexed, values - odd. It is not guaranteed that key-value pairs are always flattened in same order:

my %hash =  ( a => 1, b => 2 );
print %hash; # Maybe 'a1b2' or 'b2a1'