tokuhirom's Blog

How do you get the return value of "if" statement in Perl5?

http://d.hatena.ne.jp/rightgo09/20101114/p1

just fucking do { } it.

use 5.10.1;

my $year  = 2010;
my $month = 11;

my $nendo = do {
    if ( $month >= 4 ) {
        $year;
    }
    elsif ( $month <= 3 ) {
        $year - 1;
    }
    else {
        die;
    }
};

say $nendo;