如何打印拼写出来的月份名称而不是数字 [英] How to Print Spelled out month names rather than numbers

查看:97
本文介绍了如何打印拼写出来的月份名称而不是数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如何使Perl打印月份的名称而不是其数字:9应该显示为9月.我希望下面的程序打印月份的名称,而不是数字.

How can you get Perl to print names of months rather than their numbers for example: 9 should appear as September. I would like the program below to print names of months rather than their numbers.

#!/usr/bin/perl

use strict;
use warnings;
use Date::Easter;

print "Please enter a year";
chomp (my $year = <STDIN>);

my ($m1, $d1) = easter ($year);
my ($m2, $d2) = julian_easter ($year);
my ($m3, $d3) = orthodox_easter ($year);

print "Gregorian => Month: $m1 Day: $d1\n";
print "Julian    => Month: $m2 Day: $d2\n";
print "Orthodox  => Month: $m3 Day: $d3\n";

推荐答案

我懒得下载此模块,无法查看几个月是从0到11还是从1到12.为此,我假设几个月是从0到11.

I'm too lazy to download this module to see if months are from 0 to 11 or 1 to 12. For this, I'm assuming months are from 0 to 11.

最简单的方法是使用月份名称创建一个数组:

Easiest way is to create an array with the month names:

my @month_list = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);

my ($m1, $d1) = easter ($year);
my ($m2, $d2) = julian_easter ($year);
my ($m3, $d3) = orthodox_easter ($year);

print "Gregorian => Month: $month_list[$m1] Day: $d1\n";
print "Julian    => Month: $month_list[$m2] Day: $d2\n";
print "Orthodox  => Month: $month_list[$m3] Day: $d3\n";

如果月份的编号从1到12,则将虚假的月份添加到数组的开头:

If months are numbered from 1 to 12, add a fake month to the beginning of the array:

my @month_list = qw(Foo Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);

这篇关于如何打印拼写出来的月份名称而不是数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆