Last active
March 19, 2022 16:31
-
-
Save sironekotoro/950f6b63e43068235ac78dded0b073c3 to your computer and use it in GitHub Desktop.
サブルーチンの中身をif文の中に移して(正規表現を整理して)完成
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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use utf8; | |
use Encode qw/decode/; | |
my %era = ( | |
慶応 => 1865, | |
明治 => 1868, | |
大正 => 1912, | |
昭和 => 1926, | |
平成 => 1989, | |
令和 => 2019, | |
); | |
my $input = decode( 'utf8', $ARGV[0] ); | |
if ( $input =~ /(\w{2,2})(\w+)年/ ) { | |
if ( $2 eq '元' || $2 == 1 ) { | |
print $era{$1}; | |
} | |
else { | |
print $era{$1} + $2 - 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment