Logo

Programming-Idioms

History of Idiom 8 > diff from v59 to v60

Edit summary for version 60 by daxim:
[Perl] add docs, more precise explanation

Version 59

2019-09-27, 19:28:17

Version 60

2019-09-29, 17:27:02

Idiom #8 Initialize a new map (associative array)

Declare a new map object x, and provide some (key, value) pairs as initial content.

Idiom #8 Initialize a new map (associative array)

Declare a new map object x, and provide some (key, value) pairs as initial content.

Extra Keywords
table dictionary hash
Extra Keywords
table dictionary hash
Code
my %map = ( 
    name=>'Roboticus',
    "foo bar"=>"joe"
);
Code
my %x = ( 
    name => 'Roboticus',
    'foo bar' => 'joe'
);
Comments bubble
The '=>' operator turns the left side item into a string, so you don't need to quote the value unless it has spaces or other special characters in it.
Comments bubble
The '=>' operator autoquotes the word on its left if it begins with a letter or underscore and is composed only of letters, digits and underscores. Otherwise quotes are required.
Doc URL
http://p3rl.org/op#Comma-Operator