Skip to content

Instantly share code, notes, and snippets.

@pozorvlak
pozorvlak / gist:9c6fadd6b2afef2a83d51f4368474a8b
Created October 27, 2017 17:41
Closure weirdness in Perl
Updating a single variable in-place: closures get the new value because they fetch it from the lexical scope
$ cat closures.pl
my @closures;
for (my $i = 0; $i < 3; $i++) {
push @closures, sub { print "$i\n"; };
}
for my $fn (@closures) {
$fn->();
}