in reply to Re: Re: evaluation strategy of perl
in thread evaluation strategy of perl

The for(LIST) doesn't bind early either. However, $i is just an alias to a different value, so rather than $i itself, the closure remembers the alias. It's easily visible if we use an array rather than a literal list.
#!/usr/bin/perl -w use strict; my @t = (1,2,3); my @d; for my $i (@t) { push @d, sub { print "$i\n" }; } $_++ for @t; &$_ for @d; __END__ 2 3 4
I hadn't thought about that, though in retrospect it's quite clear. Thanks for making me ponder this.

Makeshifts last the longest.