Please let me know fast if possible.
Thanks.
set array(1,2,3,4) "My precious data"
set array(2,1,3,10) "Oh dear"
You can also use a list of lists of lists of lists:
set data {
{
{
{1 2 3}
{3 4 5}
}
{
{A V C}
{a b c d}
(a b c d e f g}
}
}
{
{
{A}
}
}
{
...
}
}
puts [lindex $data 1 2 3 4]
If you prefer random access, then an (associative) array like the first
will do nicely, I think (or a dict if you use Tcl 8.5).
If you need a more structured access, like looping over the various
dimensions, then I suggest you use nested lists. For an example of
those: see the Wiki (http://wiki.tcl.tk) and look for the page on
matrix operations ..
I guess this has the C-kind of loop handling with indices for
manipulation.
I shall check, please let me know if you have seen this before ...
But is not accesible, please do let me know, if somebody knows its
location.
Thanks, I would be really grateful.
Judging from the web page I looked at, this extension is pretty dead.
As far as I can tell, it hasn't been updated in at least 11 years and
never made it past alpha stage. Those factors pretty much guarantee
that it won't work for you.
Have you looked at NAP? I can't guarantee that it will do the job
either, but at least it's actively maintained :)
--
David N. Welton
- http://www.dedasys.com/davidw/
Apache, Linux, Tcl Consulting
- http://www.dedasys.com/
Thanks for your messages ...
I am still not able to see the beauty (correlation between) of lists of
lists and the C-style arrays. Maybe an example in TCL for 4-dimensions
and the C-style equivalent can be shown.
Also this kind of lists should be expansible dynamically as I will be
filling these lists dynamically when I am parsing a result file that
contains a lot of strings. These strings are to be arranged into the
4-D array in a specific way.
Thanks, please give me an illustration.
Here you go.
C:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main () {
char mylist[2][2][2][2][5];
strcpy(mylist[0][0][0][0], "aaaa");
strcpy(mylist[0][0][0][1], "bbbb");
strcpy(mylist[0][0][1][0], "cccc");
strcpy(mylist[0][0][1][1], "dddd");
strcpy(mylist[0][1][0][0], "eeee");
strcpy(mylist[0][1][0][1], "ffff");
strcpy(mylist[0][1][1][0], "gggg");
strcpy(mylist[0][1][1][1], "hhhh");
strcpy(mylist[1][0][0][0], "iiii");
strcpy(mylist[1][0][0][1], "jjjj");
strcpy(mylist[1][0][1][0], "kkkk");
strcpy(mylist[1][0][1][1], "llll");
strcpy(mylist[1][1][0][0], "mmmm");
strcpy(mylist[1][1][0][1], "nnnn");
strcpy(mylist[1][1][1][0], "oooo");
strcpy(mylist[1][1][1][1], "pppp");
printf("%s\n", mylist[0][1][0][1]);
exit(EXIT_SUCCESS);
}
Tcl:
set mylist {{{{aaaa bbbb} {cccc dddd}} {{eeee ffff} {gggg hhhh}}}
{{{iiii jjjj} {kkkk llll}} {{mmmm nnnn} {oooo pppp}}}}
puts [lindex $mylist 0 1 0 1]
I'll leave dynamic list expansion as an exercise for the reader. If
you're stumped, try reading the man pages for the commands that start
with the letter L.
Regards,
Arjen