Created
October 9, 2011 09:18
-
-
Save ainame/1273482 to your computer and use it in GitHub Desktop.
This file contains 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; | |
# クロージャの実装方法 | |
# count_one()とcount_so_far()は$countに束縛されたクロージャ | |
{ | |
my $count = 0; | |
sub count_one { ++$count } | |
sub count_so_far { return $count; } | |
} | |
print count_so_far() . "\n"; | |
count_one(); | |
count_one(); | |
count_one(); | |
print count_so_far() . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment