Elizabeth Mattijsen <liz@dijkmat.nl> writes:
>At 11:44 +0200 10/20/03, Elizabeth Mattijsen wrote:
>>At 23:01 +0000 10/19/03, martin@suttles.sca.sfbay.sun.com (via RT) wrote:
>>>my $count = 0;
>>>my $x = [sub() { $count },
>>> sub() { return $count },
>>> sub($) { $count += $_[0] }];
>>>$x->[2](3);
>>>printf "%d %d\n", $x->[0](), $x->[1]();
>>>
>>>This prints
>>>0 3
>>>when it should print
>>>3 3
>
>Hmmm... both of the following return correct results also:
>
>BEGIN {my $count = 'foo'}; # $foo properly initialized at compile time
No. That has initialized a $count lexical to the BEGIN
>my $x = [sub() { $count },
No lexical $count in scope here 'tis a global.
> sub() { return $count },
> sub($) { $count += $_[0] }];
>$x->[2](3);
>printf "%d %d\n", $x->[0](), $x->[1]();