How do I access one of the indices in array tst with the code below?
tst[Var,"-"VarC]=sprintf("%5.2f",Car[BCar] / 12)
When I scan thru the array with
for ( i in tst ) { print i,tst }
I get the output of:
vec-7 144
But when I try this in the END
print tst[vec-7]
It looks like it's not set.
What am I doing wrong?? Something with the SUBSEP???
Please help.
Thanks
Without quotes, "vec-7" is evaluated as "value of variable vec" minus "7", which isn't a good key for your hash.
Try this:
print tst["vec-7"]
still not getting it. Do I need to assign indices differently, maybe???
I got it.
Thanks A LOT robotronic. I changed:
tst[Var,"-"VarC]=sprintf("%5.2f",Car[BCar] / 12)
to
tst[Var"-"VarC]=sprintf("%5.2f",Car[BCar] / 12)
Then I did your code to print it with the quotes. I removed the ","
Thanks again, I was getting frustraded.
What about:
print tst["vec","-7"]
In awk an associative array could have only one dimension so, if you assign your keys with the syntax:
tst[Var,"-"VarC]= ...
The resulting key of the one-dimensional hash will be the concatenation between two values but, for some reason, it seems that you must always use "," to express the key.
To avoid problems, you should remove the comma in the key value, assigning the value in a way like this:
tst[Var"-"VarC]
Try and see
Oh, I see that you found the solution by yourself while I was writing
Good
Thanks again, I found it with your help.