programming-examples/perl/Subroutine/Closure in action.pl
2019-11-15 12:59:38 +01:00

14 lines
286 B
Perl

sub paint {
my $color = shift;
my $ref = sub {
my $object=shift;
print "Paint the $object $color.\n"; # $color still in scope
};
return $ref;
}
my $p1=paint("red");
my $p2=paint("blue");
$p1->("flower");
$p2->("sky");