Created
November 5, 2010 16:33
-
-
Save koba04/664406 to your computer and use it in GitHub Desktop.
sample of closure by perl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
sub make_closure { | |
my $cnt = 0; | |
return sub { | |
++$cnt; | |
} | |
} | |
my $closure1 = make_closure; | |
my $closure2 = make_closure; | |
print "closure1 => " . $closure1->() . $closure1->() . "\n"; | |
print "closure2 => " . $closure2->() . $closure2->() . $closure2->() . "\n"; | |
# closure1 => 12 | |
# closure2 => 123 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment