slang-users mailing list

[2010 Date Index] [2010 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

[slang-users] Preserving order in an associative array


Hi,

It seemed to me that it could be useful to split a file into a number of
strings and then split these strings into an associative array, do something
on one of these strings based on its linkage to the other and then finally
assemble it all back into the file. But if, just to illustrate, I do;

   variable S = Assoc_Type[String_Type];
   variable k, v, s, file;
   variable a = String_Type[0];
   
   S["a"] = "b";
   S["b"] = "c";
   S["d"] = "e";

   foreach k, v (S) using ("keys", "values")
     {  
        s = strcat (k, v);
        a = [a, s];
     }
   
   file = strjoin (a, "\n");

and I output this, I get;

  ab
  de
  bc

i.e. the order in which I entered the pairs is not preserved. Please
note, that I do not want any kind of sorting, I just want to preserve the
original order in which the keys and values were entered into the array.


Thanks,

Morten



[2010 date index] [2010 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]