Skip to content

Instantly share code, notes, and snippets.

@karupanerura
Created October 28, 2013 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karupanerura/7194399 to your computer and use it in GitHub Desktop.
Save karupanerura/7194399 to your computer and use it in GitHub Desktop.
static variable be undef if throw when initialize static variable.
use strict;
use warnings;
use utf8;
use feature qw/state/;
use Try::Tiny;
sub yyy {
state $f = 0;
die "DIE!!" unless $f++;
return $f;
}
sub xxx {
state $x = yyy();
return $x;
}
for (1..3) {
my $x;
try {
$x = xxx();
}
catch {
warn "catch: $_";
};
warn "x = $x";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment