Perl Language Lists Assigning a list to a hash


Example

Lists can also be assigned to hash variables. When creating a list that will be assigned to a hash variable, it is recommended to use the fat comma => between keys and values to show their relationship:

my %hash = ( foo => 42, bar => 43, baz => 44 );

The => is really only a special comma that automatically quotes the operand to its left. So, you could use normal commas, but the relationship is not as clear:

my %hash = ( 'foo', 42, 'bar', 43, 'baz', 44 );

You can also use quoted strings for the left hand operand of the fat comma =>, which is especially useful for keys containing spaces.

my %hash = ( 'foo bar' => 42, 'baz qux' => 43 );

For details see Comma operator at perldoc perlop.