Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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]}
33If 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]}
33I 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.

![]() |
![]() |
![]() |

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