On Sat, 08 Dec 2007 14:23:40 -0800, lihao0129@[EMAIL PROTECTED]
wrote:
> On Dec 8, 5:08 pm, Steffen Schuler <schuler.stef...@[EMAIL PROTECTED]
>
> wrote:
>> On Sat, 08 Dec 2007 13:57:53 -0800, lihao0...@[EMAIL PROTECTED]
wrote:
>> > I am trying to initialize an associate array with awk, for example,
>> > to map literal months to numeric months, I did something like:
>>
>> > BEGIN {
>> > mon["Jan"] = 1; .....; mon["Dec"] = 12;
>> > }
>>
>> > Is there some other ways to do this with awk(gawk)?? for example, in
>> > Perl , I can do things like:
>>
>> > my %mon = ();
>> > @[EMAIL PROTECTED]
qw/Jan Feb Mar Apr May.... / } = (1..12);
>>
>> > Thanks in advance,
>> > LH
>>
>> use:
>>
>> split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec", mon, " ")
>>
>>
> Hi, Steffen:
> thank you for your reply:) but this seems give me an array which has:
>
> mon[1] = "Jan"; mon[2] = "Feb"; .....
>
> what I really want is:
>
> mon["Jan"] = 1; mon["Feb"] = 2; .....
>
> Any other solution?? many thanks:)
>
> LH
>
>> /home/steffen/usenet-signature- Hide quoted text -
>>
>> - Show quoted text -
see also my last post.
use:
split("Jan Feb Mar Apr May....", moninv, " ")
for (i in mon) mon[moninv[i]] = i
--
Steffen


|