perl closure

前端之家收集整理的这篇文章主要介绍了perl closure前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#!/usr/bin/perl use strict; use warnings; sub make_saying {         my $salute = shift;         my $newfunc = sub {                 my $target = shift;                 print "$salute,$target!\n";         };         return $newfunc; # Return a closure } my $f = make_saying("Howdy"); # Create a closure my $g = make_saying("Greetings"); # Create another closure my $h = make_saying("Hello"); # Time passes... $f->("world"); $g->("earthlings"); $h->("Jason");

猜你在找的Perl相关文章