In a message dated Fri, 7 Sep 2007, Wim Vanderbauwhede writes:

On 07/09/2007, Chas Owens <[EMAIL PROTECTED]> wrote:
Even
if strict weren't in effect this code should not work since the $x in
the closure is not the one created after the closure:

perl -le 'my$r=sub{print $x+1};my $x = 2;$r->()'

That Perl 5 code prints 1 because undef plus one is one.


I am sorry, but if you put it in a script that Perl 5 code prints 3:
[wv]$ cat test_softref.pl
my $r=sub {print $x+1,"\n" };
my $v='x';
$$v=2;
&$r();
[wv]$ perl test_softref.pl
3
[wv]$

Putting it into a script isn't all you changed. As your filename implies, you're using a symbolic reference (sometimes called a "soft" reference) in this Perl 5 code. Your Perl 6 doesn't have any symbolic references. Your Perl 6 closure refers to a variable, $x, that has not yet been declared, which is illegal; the fact that there is a $x by runtime is irrelevant. Perl (5 or 6) is not Tcl; it is compile time that matters for variable binding, not runtime (unless you specifically delay the binding somehow to runtime).

Trey

Reply via email to