Newsgroups: comp.lang.perl
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!hellgate.utah.edu!csn!convex!usenet
From: Tom Christiansen <tchrist@convex.COM>
Subject: Re: perl 4.0 patch #1
Message-ID: <1991Apr25.182103.20549@convex.com>
Sender: usenet@convex.com (news access account)
Nntp-Posting-Host: pixel.convex.com
Reply-To: tchrist@convex.COM (Tom Christiansen)
Organization: CONVEX Software Development, Richardson, TX
References: <550@appserv.Eng.Sun.COM> <3012@weber.sw.mcc.com> <18285@sunquest.UUCP>
Date: Thu, 25 Apr 1991 18:21:03 GMT
Lines: 33

From the keyboard of jew@rt.uucp (/87336):
:
:In the process of learning perl, I have translated an awk script I wrote.
:I figured there is a better way to do this:
:
:# define an array of months
:$Calendar{'Jan'} = '01';
:$Calendar{'Feb'} = '02';
:$Calendar{'Mar'} = '03';
:$Calendar{'Apr'} = '04';
:$Calendar{'May'} = '05';
:$Calendar{'Jun'} = '06';
:$Calendar{'Jul'} = '07';
:$Calendar{'Aug'} = '08';
:$Calendar{'Sep'} = '09';
:$Calendar{'Oct'} = '10';
:$Calendar{'Nov'} = '11';
:$Calendar{'Dec'} = '12';
:
:Here's your chance to show your elegance!  What's the best way to define
:this array?

How about:

 @Calendar{Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec} = ('01'..'12');

You can have quotes around each month, and I prefer it that way, but then
it wouldn't fit on one line. :-)   Oddly enough, you can't leave them off
the numbers though, since '01'..'12' is not the same as 01..12: you'd lose
the leading zeros you seem to want.


--tom
