Skip to content

Instantly share code, notes, and snippets.

@papix
Last active March 4, 2022 13:01
Show Gist options
  • Select an option

  • Save papix/0cf6e1be5cfdf7717d3bdea3ec050fc6 to your computer and use it in GitHub Desktop.

Select an option

Save papix/0cf6e1be5cfdf7717d3bdea3ec050fc6 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use utf8;
use Encode;
my $gengo = {
'慶応' => 1865,
'明治' => 1868,
'大正' => 1912,
'昭和' => 1926,
'平成' => 1989,
'令和' => 2019,
};
my $input = decode_utf8(shift @ARGV);
if ($input =~ /\A(.+?)(\d+|元)年\z/) {
my $gengou = $1;
my $year = $2 eq '元' ? 1 : $2 - 1;
my $first_year = $gengo->{$gengou};
print $first_year + $year;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment