Be aware that at least in 5.5.3 and earlier, this list is split at runtime causing some performance penalty if invoked repeatedly. You can do the split once at compile time by wrapping a subroutine inside a BEGIN block:{ my $mn = 3; my $month = (qw(January Feburary March April May June July August S +eptember October November December))[$mn]; print $month, "\n"; }
BEGIN { my @month_names = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec +); sub month_name_for { my $number = shift; die if $number < 0 or $number > $#month_names or $number != int($n +umber); $month_names[$number]; } }
-- Randal L. Schwartz, Perl hacker
In reply to RE: (jcwren) Re: Month Names
by merlyn
in thread Month Names
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |