September 2017
Beginner
402 pages
9h 52m
English
The pair of curly braces ({ }) create either an empty hash or a code block. Perl 6 decides what to do based on the code it sees between the braces.
In the following examples, you may see that Perl 6 does what you mean.
Empty braces or a list of key value pairs create a hash, as shown in the following code:
say {}.WHAT; # (Hash)say {a => 1, b => 2}.WHAT; # (Hash)
While some executable code, referring to placeholder, or default variables creates a code block:
say {say 1}.WHAT; # (Block)say {$^x * $^y}.WHAT; # (Block)say {$_}.WHAT; # (Block)say {$_ => 1}.WHAT; # (Block)
Notice that because Perl 6 uses the same curly braces in both hash and block syntax, some confusion may take place, compare the following two ...
Read now
Unlock full access