%
ErrorsCollection

%

Synthesised documentation from language/variables

From language/variables

See Original text in context

In addition, there's an Associative anonymous state variable %.

sub foo($x{
    say (%).push($x => $x);
}
 
foo($_for ^3;
 
# OUTPUT: «{0 => 0} 
#          {0 => 0, 1 => 1} 
#          {0 => 0, 1 => 1, 2 => 2}␤»

The same caveat about disambiguation applies. As you may expect, indexed access is also possible (with copying to make it useful).

sub foo($x{
    my $v = %;
    $v{$x} = $x;
    say $v;
}
 
foo($_for ^3;
 
# OUTPUT: «{0 => 0} 
#          {0 => 0, 1 => 1} 
#          {0 => 0, 1 => 1, 2 => 2}␤»

As with the other anonymous state variables, each mention of % within a given scope will effectively introduce a separate variable.