Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

from tawk to gawk - multidimensional arrays

Status
Not open for further replies.

Cornelius19

Technical User
Mar 9, 2007
26
Hi,

I use gawk but need to run an old awk script, written for the tawk compiler ( The syntax is slightly different, for instance, they declare multi-dimensional arrays like this:

Code:
ary[word][dialect][24] = "A";

This does not compile under gawk, but I can easily convert it to standard awk syntax and it compiles (I hope this is the correct translation):

Code:
ary[word,dialect,24] = "A";

I could correct most of the errors with such a change. However, there are still a couple of errors I do not know how to correct (basically where the above mentioned tri-dimensional array is used with less than 3 dimensions):

Code:
for (dialect in ary[word])

or

Code:
if (24 in ary[word,dialect] && substr($0,24,1)!="C")

Do you have any idea?

Cornelius
 
Hi

That is impossible in [tt]gawk[/tt]. There are only simulated multi-dimensional arrays, not real ones.
Code:
ary[word,dialect,24] = "A";

[gray]# is equivalent with[/gray]

ary[word SUBSEP dialect SUBSEP 24] = "A";

[gray]# and by default is equivalent with[/gray]

ary[word "\034" dialect "\034" 24] = "A";
As you can see, the multiple indexes are concatenated into one and the array is infact single dimensional.

I am afraid, the closest dialect to convert that [tt]tawk[/tt] script into, would be [tt]perl[/tt]. :-(

Feherke.
 
Thanks for the post. I understood that this is only a simulated multi-dimensional array and in reality it is a single dimensional array with indexes concatenated into a single one. However, in this case, I might not need multi-dimensional arrays, just brake the single index into substrings. Could not something like that work?

Cornelius
 
Thanks a lot Feherke. I will try to explore the perl option.

Cornelius

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top