in reply to Array indices
my @months = qw[ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ];So, you can see that when accessing $month[2] that 'Mar' is the result. It's possible to put in a dummy month, such as like this:
my @months = '',qw[ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ];This would work, however, stepping back from the problem, you'll note there's little reason to label January as 1 internally. Look at localtime as an example of how it can be done. In that case, January is month 0.
print "Today is in the month ",$month[$calendar_month-1],"\n";Which is straightforward enough. Wrapped in a function, it becomes even less of an issue:
sub get_month_name { my ($calendar_month) = @_; return $month[$calendar_month-1]; }
|
|---|