perl closure 闭包
发布时间:2020-12-15 21:01:35 所属栏目:大数据 来源:网络整理
导读:[root@dou shili]# cat closure.pl #!/usr/bin/perl -w use strict; sub outer { ??????? my $color = shift; ??????? my $ref = sub { ??????????????? my $object = shift; ??????????????? print "paint the $object $color.n"; ??????? }; return $ref;
[root@dou shili]# cat closure.pl sub outer { ??????? my $color = shift; ??????? my $ref = sub { ??????????????? my $object = shift; ??????????????? print "paint the $object $color.n"; ??????? }; return $ref; # returns a closure. } my $p1 = outer("red"); my $p2 = outer("blue"); $p1->("flower"); $p2->("sky"); [root@dou shili]# perl closure.pl paint the flower red. paint the sky blue. ? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |