Computing.Net > Forums > Unix > arrayed arrays !!

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

arrayed arrays !!

Reply to Message Icon

Name: hernandez
Date: January 18, 2003 at 06:48:40 Pacific
OS: w98se
CPU/Ram: 128
Comment:

Hi

Can you make an array of an array ?

Example:
I have the array LOTTERY_LINE[x] which contains a line of numbers like 1,2,3,4,5,6.
I want to reference each number seperately - I know how to do this and can assign each number to a variable - but can I assign them to an array like this
LOTTRY_LINE[x]_NUMBER[y]
(spelling is intentional - I do not want to assign to original array - just need to know if it is possible to do something like this.)

I tried doing it and it returns an error

I'm in korn shell



Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: January 18, 2003 at 08:39:56 Pacific
Reply:

No, those are single dimension arrays. But you can store your whole lines in an array like you are doing now, and pull one of those lines into a second array so that the numbers can be arrayed. Here is an example where the stored lines have space-delimited numbers:

line=4
LOTTERY_LINE[$line]="11 22 33 44 55 66"
print ${LOTTERY_LINE[4]}
11 22 33 44 55 66
set -A NBR ${LOTTERY_LINE[4]}
print ${NBR[2]}
33

If you want comma-delimited numbers:

LOTTERY_LINE[$line]=11,22,33,44,55,66
set -A NBR $(print ${LOTTERY_LINE[$line]}|sed "s/,/ /g")
print ${NBR[2]}
33

I had to pipe the line through sed to change the commas to spaces. I tried to eliminate the need for sed here by changing IFS to a comma, such as:

IFS=, set -A NBR ...

but the set command still used spaces as field delimiter.


0

Response Number 2
Name: hernandez
Date: January 19, 2003 at 03:31:54 Pacific
Reply:

cheers - that's a much better, and faster way than i did it in the end.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: arrayed arrays !!

array in Borne Shell www.computing.net/answers/unix/array-in-borne-shell/3957.html

using arrays in a while statement ? www.computing.net/answers/unix/using-arrays-in-a-while-statement-/5003.html

About arrays www.computing.net/answers/unix/about-arrays/6014.html