We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 90f7097 commit c71c154Copy full SHA for c71c154
doc/Language/variables.pod6
@@ -630,13 +630,17 @@ Many operators come with implicit binding which can lead to actions at a distanc
630
Use C<.clone> or coercion to create a new container that can be bound to.
631
632
my @a;
633
+ my @a-cloned;
634
sub f() {
635
state $i;
636
$i++;
- @a.push: "k$i" => $i # <-- .clone goes here
637
+ @a\ .push: "k$i" => $i;
638
+ @a-cloned.push: "k$i" => $i.clone;
639
};
640
+
641
f for 1..3;
- dd @a; # OUTPUT: «Array @a = [:k1(3), :k2(3), :k3(3)]»
642
+ say @a; # OUTPUT: «[k1 => 3 k2 => 3 k3 => 3]»
643
+ say @a-cloned; # OUTPUT: «[k1 => 1 k2 => 2 k3 => 3]»
644
645
State variables are shared between all threads. The result can be unexpected.
646
0 commit comments