Raku Books / Perl 6 at a Glance / Code Organization
Placeholders
When an anonymous code block is created, declaring a list of
arguments is not mandatory even when a block takes an argument. To let
this happen, Perl 6 uses special variable containers, which come with
the ^ twigil. This is similar to the predefined variables
$a and $b in Perl 5.
In the case of more than one argument, their actual order corresponds
to the alphabetical order of the names of the ^-ed
variables.
my $pow = {$^x ** $^y};
say $pow(3, 4); # 81CodeBlockPlaceholder2raku for 0..9 { say “$^n2, $^n1”; } CodeBlockPlaceholder3raku my $pow = {$:base ** $:exp}; say $pow(:base(25), :exp(2)); # 625 CodeBlockPlaceholder4raku-static say $pow(:exp(2), :base(25)); # 625 CodeBlockPlaceholder5raku-static sub f($a) { # say $^a; # Error: Redeclaration of symbol ‘$^a’ # as a placeholder parameter } CodeBlockPlaceholder6raku-static sub f($a) { say $^b; # Placeholder variable ‘$^b’ cannot # override existing signature } ```