Ben Morrow wrote:

...but that's just a braino on Matt's part, and his point still stands
for the code

    package Test;
sub apply {
        my $func = shift;
        $func->(shift) while @_;
    }

    package Foo;
    use vars qw/$line/; # can't use our as that also creates a lexical :(

    $line = 0;
    my $func = sub {
        print $line++, ' ', shift(), "\n";
    };

    Test::apply($func, qw(a b c d));

In this case $func picks up $Foo::line rather than $Test::line or
$::line, even though it's anonymous.

It's still a closure. Perl 5 just isn't a good example here, since all anonymous subs are closures.

Allison

Reply via email to