Skip to content

Instantly share code, notes, and snippets.

@jadiunr
Last active May 7, 2019
Embed
What would you like to do?
暗号
use strict;
use warnings;
use utf8;
use Time::Piece 'localtime';
use JSON::XS 'decode_json';
use Encode 'encode_utf8';
my $eras = decode_json(encode_utf8 '[{"date":"0650/02/15","era":"白雉"},{"date":"0686/07/20","era":"朱鳥"},{"date":"0701/03/21","era":"大宝"},{"date":"0704/05/10","era":"慶雲"},{"date":"0708/01/11","era":"和銅"},{"date":"0717/11/17","era":"養老"},{"date":"0724/02/04","era":"神亀"},{"date":"0729/08/05","era":"天平"},{"date":"0749/04/14","era":"天平感宝"},{"date":"0749/07/02","era":"天平勝宝"},{"date":"0757/08/18","era":"天平宝字"},{"date":"0765/01/07","era":"天平神護"},{"date":"0767/08/16","era":"神護景雲"},{"date":"0770/10/01","era":"宝亀"},{"date":"0781/01/01","era":"天応"},{"date":"0782/08/19","era":"延暦"},{"date":"0810/09/19","era":"弘仁"},{"date":"0824/01/05","era":"天長"},{"date":"0834/01/03","era":"承和"},{"date":"0848/06/13","era":"嘉祥"},{"date":"0851/04/28","era":"仁寿"},{"date":"0854/11/30","era":"斎衡"},{"date":"0857/02/21","era":"天安"},{"date":"0859/04/15","era":"貞観"},{"date":"0877/04/16","era":"元慶"},{"date":"0885/02/21","era":"仁和"},{"date":"0889/04/27","era":"寛平"},{"date":"0898/04/26","era":"昌泰"},{"date":"0901/07/15","era":"延喜"},{"date":"0923/04/11","era":"延長"},{"date":"0931/04/26","era":"承平"},{"date":"0938/05/22","era":"天慶"},{"date":"0947/04/22","era":"天暦"},{"date":"0957/10/27","era":"天徳"},{"date":"0961/02/16","era":"応和"},{"date":"0964/07/10","era":"康保"},{"date":"0968/08/13","era":"安和"},{"date":"0970/03/25","era":"天禄"},{"date":"0973/12/20","era":"天延"},{"date":"0976/07/13","era":"貞元"},{"date":"0978/11/29","era":"天元"},{"date":"0983/04/15","era":"永観"},{"date":"0985/04/27","era":"寛和"},{"date":"0987/04/05","era":"永延"},{"date":"0989/08/08","era":"永祚"},{"date":"0990/11/07","era":"正暦"},{"date":"0995/02/22","era":"長徳"},{"date":"0999/01/13","era":"長保"},{"date":"1004/07/20","era":"寛弘"},{"date":"1012/12/25","era":"長和"},{"date":"1017/04/23","era":"寛仁"},{"date":"1021/02/02","era":"治安"},{"date":"1024/07/13","era":"万寿"},{"date":"1028/07/25","era":"長元"},{"date":"1037/04/21","era":"長暦"},{"date":"1040/11/10","era":"長久"},{"date":"1044/11/24","era":"寛徳"},{"date":"1046/04/14","era":"永承"},{"date":"1053/01/11","era":"天喜"},{"date":"1058/08/29","era":"康平"},{"date":"1065/08/02","era":"治暦"},{"date":"1069/04/13","era":"延久"},{"date":"1074/08/23","era":"承保"},{"date":"1077/11/17","era":"承暦"},{"date":"1081/02/10","era":"永保"},{"date":"1084/02/07","era":"応徳"},{"date":"1087/04/07","era":"寛治"},{"date":"1094/12/15","era":"嘉保"},{"date":"1096/12/17","era":"永長"},{"date":"1097/11/21","era":"承徳"},{"date":"1099/08/28","era":"康和"},{"date":"1104/02/10","era":"長治"},{"date":"1106/04/09","era":"嘉承"},{"date":"1108/08/03","era":"天仁"},{"date":"1110/07/13","era":"天永"},{"date":"1113/07/13","era":"永久"},{"date":"1118/04/03","era":"元永"},{"date":"1120/04/10","era":"保安"},{"date":"1124/04/03","era":"天治"},{"date":"1126/01/22","era":"大治"},{"date":"1131/01/29","era":"天承"},{"date":"1132/08/11","era":"長承"},{"date":"1135/04/27","era":"保延"},{"date":"1141/07/10","era":"永治"},{"date":"1142/04/28","era":"康治"},{"date":"1144/02/23","era":"天養"},{"date":"1145/07/22","era":"久安"},{"date":"1151/01/26","era":"仁平"},{"date":"1154/10/28","era":"久寿"},{"date":"1156/04/27","era":"保元"},{"date":"1159/04/20","era":"平治"},{"date":"1160/01/10","era":"永暦"},{"date":"1161/09/04","era":"応保"},{"date":"1163/03/29","era":"長寛"},{"date":"1165/06/05","era":"永万"},{"date":"1166/08/27","era":"仁安"},{"date":"1169/04/08","era":"嘉応"},{"date":"1171/04/21","era":"承安"},{"date":"1175/07/28","era":"安元"},{"date":"1177/08/04","era":"治承"},{"date":"1181/07/14","era":"養和"},{"date":"1182/05/27","era":"寿永"},{"date":"1184/04/16","era":"元暦"},{"date":"1185/08/14","era":"文治"},{"date":"1199/04/27","era":"正治"},{"date":"1201/02/13","era":"建仁"},{"date":"1204/02/20","era":"元久"},{"date":"1206/04/27","era":"建永"},{"date":"1207/10/25","era":"承元"},{"date":"1211/03/09","era":"建暦"},{"date":"1213/12/06","era":"建保"},{"date":"1219/04/12","era":"承久"},{"date":"1222/04/13","era":"貞応"},{"date":"1224/11/20","era":"元仁"},{"date":"1225/04/20","era":"嘉禄"},{"date":"1227/12/10","era":"安貞"},{"date":"1229/03/05","era":"寛喜"},{"date":"1232/04/02","era":"貞永"},{"date":"1233/04/15","era":"天福"},{"date":"1234/11/05","era":"文暦"},{"date":"1235/09/19","era":"嘉禎"},{"date":"1238/11/23","era":"暦仁"},{"date":"1239/02/07","era":"延応"},{"date":"1240/07/16","era":"仁治"},{"date":"1243/02/26","era":"寛元"},{"date":"1247/02/28","era":"宝治"},{"date":"1249/03/18","era":"建長"},{"date":"1256/10/05","era":"康元"},{"date":"1257/03/14","era":"正嘉"},{"date":"1259/03/26","era":"正元"},{"date":"1260/04/13","era":"文応"},{"date":"1261/02/20","era":"弘長"},{"date":"1264/02/28","era":"文永"},{"date":"1275/04/25","era":"建治"},{"date":"1278/02/29","era":"弘安"},{"date":"1288/04/28","era":"正応"},{"date":"1293/08/05","era":"永仁"},{"date":"1299/04/25","era":"正安"},{"date":"1302/11/21","era":"乾元"},{"date":"1303/08/05","era":"嘉元"},{"date":"1306/12/14","era":"徳治"},{"date":"1308/10/09","era":"延慶"},{"date":"1311/04/28","era":"応長"},{"date":"1312/03/20","era":"正和"},{"date":"1317/02/03","era":"文保"},{"date":"1319/04/28","era":"元応"},{"date":"1321/02/23","era":"元亨"},{"date":"1324/12/09","era":"正中"},{"date":"1326/04/26","era":"嘉暦"},{"date":"1329/08/29","era":"元徳"},{"date":"1331/08/09","era":"元弘"},{"date":"1332/04/28","era":"正慶"},{"date":"1334/01/29","era":"建武"},{"date":"1336/02/29","era":"延元"},{"date":"1338/08/28","era":"暦応"},{"date":"1340/04/28","era":"興国"},{"date":"1342/04/27","era":"康永"},{"date":"1345/10/21","era":"貞和"},{"date":"1346/12/08","era":"正平"},{"date":"1350/02/27","era":"観応"},{"date":"1352/09/27","era":"文和"},{"date":"1356/03/28","era":"延文"},{"date":"1361/03/29","era":"康安"},{"date":"1362/09/23","era":"貞治"},{"date":"1368/02/18","era":"応安"},{"date":"1370/07/24","era":"建徳"},{"date":"1372/04/01","era":"文中"},{"date":"1375/05/27","era":"天授"},{"date":"1375/02/27","era":"永和"},{"date":"1379/03/22","era":"康暦"},{"date":"1381/02/10","era":"弘和"},{"date":"1381/02/24","era":"永徳"},{"date":"1384/04/28","era":"元中"},{"date":"1384/02/27","era":"至徳"},{"date":"1387/08/23","era":"嘉慶"},{"date":"1389/02/09","era":"康応"},{"date":"1390/03/26","era":"明徳"},{"date":"1394/07/05","era":"応永"},{"date":"1428/04/27","era":"正長"},{"date":"1429/09/05","era":"永享"},{"date":"1441/02/17","era":"嘉吉"},{"date":"1444/02/05","era":"文安"},{"date":"1449/07/28","era":"宝徳"},{"date":"1452/07/25","era":"享徳"},{"date":"1455/07/25","era":"康正"},{"date":"1457/09/28","era":"長禄"},{"date":"1460/12/21","era":"寛正"},{"date":"1466/02/28","era":"文正"},{"date":"1467/03/05","era":"応仁"},{"date":"1469/04/28","era":"文明"},{"date":"1487/07/20","era":"長享"},{"date":"1489/08/21","era":"延徳"},{"date":"1492/07/19","era":"明応"},{"date":"1501/02/29","era":"文亀"},{"date":"1504/02/30","era":"永正"},{"date":"1521/08/23","era":"大永"},{"date":"1528/08/20","era":"享禄"},{"date":"1532/07/29","era":"天文"},{"date":"1555/10/23","era":"弘治"},{"date":"1558/02/28","era":"永禄"},{"date":"1570/04/23","era":"元亀"},{"date":"1592/12/08","era":"文禄"},{"date":"1596/10/27","era":"慶長"},{"date":"1624/02/30","era":"寛永"},{"date":"1644/12/16","era":"正保"},{"date":"1648/02/15","era":"慶安"},{"date":"1652/09/18","era":"承応"},{"date":"1655/04/13","era":"明暦"},{"date":"1658/07/23","era":"万治"},{"date":"1661/04/25","era":"寛文"},{"date":"1673/09/21","era":"延宝"},{"date":"1681/09/29","era":"天和"},{"date":"1684/02/21","era":"貞享"},{"date":"1688/09/30","era":"元禄"},{"date":"1704/03/13","era":"宝永"},{"date":"1711/04/25","era":"正徳"},{"date":"1716/06/22","era":"享保"},{"date":"1736/04/28","era":"元文"},{"date":"1741/02/27","era":"寛保"},{"date":"1744/02/21","era":"延享"},{"date":"1748/07/12","era":"寛延"},{"date":"1751/10/27","era":"宝暦"},{"date":"1764/06/02","era":"明和"},{"date":"1772/11/16","era":"安永"},{"date":"1781/04/02","era":"天明"},{"date":"1789/01/25","era":"寛政"},{"date":"1801/02/05","era":"享和"},{"date":"1804/02/11","era":"文化"},{"date":"1818/04/22","era":"文政"},{"date":"1830/12/10","era":"天保"},{"date":"1844/12/02","era":"弘化"},{"date":"1848/02/28","era":"嘉永"},{"date":"1854/11/27","era":"安政"},{"date":"1860/03/18","era":"万延"},{"date":"1861/02/19","era":"文久"},{"date":"1864/02/20","era":"元治"},{"date":"1865/04/07","era":"慶応"},{"date":"1868/09/08","era":"明治"},{"date":"1912/07/30","era":"大正"},{"date":"1926/12/25","era":"昭和"},{"date":"1989/01/08","era":"平成"},{"date":"2019/05/01","era":"令和"}]');
my ($y, $m, $d) = @ARGV == 3 ? map { sprintf("%0${_}d", shift @ARGV) } (4,2,2) : split(/\-/, localtime->date);
my $now_era = (grep { join('', split(/\//, $_->{date})) <= $y.$m.$d } @$eras)[-1];
print encode_utf8 "${y}${m}${d}$now_era->{era}です\n";
=encoding utf8
=head1 NAME
元号判定プログラム
=head1 USAGE
perl erajudge.pl <year> <month> <day>
引数が無い場合は現在時刻が使用される
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment