Skip to content

Instantly share code, notes, and snippets.

@Cside
Created March 31, 2011 02:30
Show Gist options
  • Save Cside/895725 to your computer and use it in GitHub Desktop.
Save Cside/895725 to your computer and use it in GitHub Desktop.
use_scalar_lazy.pl
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