INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

build a varibale name with value included into an array

build a varibale name with value included into an array

build a varibale name with value included into an array

(OP)
I need to use the name of a variable that I create using the character included into an array.

The arrayRN contains "a,b,c,d,e,f,g,h,i,l,m,n,o,p"
and with a for loop I would use each time a different value for DN and RN variable like DNa, RNa, DNb, RNb, DNc, RNc and so on

for (i in arrayRN) {
DN<here I have to put value of the array that could be from a to q> =substr($3,1,length($3)-1)
if (NF==12) {
RN<here I have to put value of the array that could be from a to q> = $12
}
else {
RN<here I have to put value of the array that could be from a to q> = ""
}
getline
if ($0 ~/Origine =/) {
break
}
}

I tried with:
RN{arrayRN[i]}
RN[arrayRN[i]]
RN(arrayRN[i])

Is there any way to do it?

Thanks

Massimo

RE: build a varibale name with value included into an array

Hi

The second is the one that should work : RN[arrayRN[i]]. Then you will get the array elements like RN["a"] populated.

If you want to have exactly RNa name like you mentioned, SYMTAB["RN" arrayRN[i]] will do it, but that will not work in all Awk implementations.

Feherke.
feherke.ga

RE: build a varibale name with value included into an array

(OP)
HI,
I've tried with this

BEGIN {
stringa_RN="a,b,c,d,e,f,g,h,i,l,m,n,o,p,q"
split(stringa_RN,arrayRN,",")
}

{

for (i in arrayRN) {

SYMTAB["RN" arrayRN[i] = "prova"
print SYMTAB["RN" arrayRN[i]
}

}



and I obtain the following error:

gawk: test_array.awk:12: SYMTAB["RN" arrayRN[i] = "prova"
gawk: test_array.awk:12: ^ syntax error
gawk: test_array.awk:14: print SYMTAB["RN" arrayRN[i]
gawk: test_array.awk:14: ^ unexpected newline or end of string

I'm using the gawk for Windows.

Thanks

massimo

RE: build a varibale name with value included into an array

Hi

There are minor syntax errors in your code :

CODE --> Awk

{
    for (i in arrayRN) {

        SYMTAB["RN" arrayRN[i]] = "prova"
        print SYMTAB["RN" arrayRN[i]]
    }

} 

Feherke.
feherke.ga

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close