Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: How to init...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 11 Topic 2098 of 2341
Post > Topic >>

Re: How to initialize an associate array nicely with awk

by Steffen Schuler <schuler.steffen@[EMAIL PROTECTED] > Dec 8, 2007 at 10:25 PM

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
 




 11 Posts in Topic:
How to initialize an associate array nicely with awk
"lihao0129@[EMAIL PR  2007-12-08 13:57:53 
Re: How to initialize an associate array nicely with awk
Steffen Schuler <schul  2007-12-08 22:08:17 
Re: How to initialize an associate array nicely with awk ---
Steffen Schuler <schul  2007-12-08 22:10:42 
Re: How to initialize an associate array nicely with awk ---
Steffen Schuler <schul  2007-12-08 22:15:34 
Re: How to initialize an associate array nicely with awk
Steffen Schuler <schul  2007-12-08 22:19:34 
Re: How to initialize an associate array nicely with awk
"lihao0129@[EMAIL PR  2007-12-08 14:23:40 
Re: How to initialize an associate array nicely with awk
Steffen Schuler <schul  2007-12-08 22:25:15 
Re: How to initialize an associate array nicely with awk
"lihao0129@[EMAIL PR  2007-12-08 14:28:09 
Re: How to initialize an associate array nicely with awk
Ted Davis <tdavis@[EMA  2007-12-08 19:56:55 
Re: How to initialize an associate array nicely with awk
Grant <g_r_a_n_t_@[EMA  2007-12-09 13:16:31 
Re: How to initialize an associate array nicely with awk
Ted Davis <tdavis@[EMA  2007-12-09 10:52:12 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Aug 27 17:56:48 CDT 2008.