Skip to content

Instantly share code, notes, and snippets.

@sironekotoro
Last active March 19, 2022 16:31
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 sironekotoro/950f6b63e43068235ac78dded0b073c3 to your computer and use it in GitHub Desktop.
Save sironekotoro/950f6b63e43068235ac78dded0b073c3 to your computer and use it in GitHub Desktop.
サブルーチンの中身をif文の中に移して(正規表現を整理して)完成
#!/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