Created
March 31, 2011 02:30
-
-
Save Cside/895725 to your computer and use it in GitHub Desktop.
use_scalar_lazy.pl
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
use Scalar::Lazy qw/lazy/; | |
# 遅延評価 | |
my $var1 = lazy { 1 }; | |
print $var1; #=> 1 | |
# シングルトン化することもできる | |
my $var2 = lazy { $something_heavy->() } 'init'; | |
print $var2; | |
print $var2; # $something_heavy->() が一度しか実行されない |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment