Page 1 of 1

Purging array data from a script?

Posted: Mon Sep 06, 2010 2:38 am
by magice
In creating scripts to write array data to a txt file, and reading that text file back to reload the array, I ran into a frustrating problem. When I wrote to the text file i kept getting an odd space between 2 of the lines of data. This space of course would cause the data to load improperly. After hours of going over the same code again and again I had an epiphany. My array must have an element with no value that i somehow initialized (probably with a typo) in my original script. so I naturally changed the name of the array, and the problem was solved.
Now my question is, is there any way to purge my stack of that original array data? It bothers me that my stack will be using more resources that it needs.

Re: Purging array data from a script?

Posted: Mon Sep 06, 2010 8:35 am
by Mark
Hi Magice,

An array is a special data type. If you write it to a file, your data will probably be incomplete and definitely scrambled. If you are using a very complex array --which you don't seem to be doing-- the data wouldn't be in any readable form. To write array data to a file correctly, e.g. to be able to import it in a word processor, you need to transform the array data into a normal string, using the combine command (look up combine in the Rev dictionary). Once the data has been transformed into plain text, you can write it to and read it from a text file.

If your goal is not to write human-readable data but if all you want is to save the data for later use in RunRev, you can use the arrayEncode and arrayDecode functions. These are pretty simple to use:

Code: Select all

-- example with Mac path
put arrayEncode(myArray) into url "binfile:~/desktop/file.dat" 

-- example with DOS path
put arrayDecode(url "binfile:C:/documents and setting/user/my documents/file.dat") into myArray
Now, if you want to delete an element, you can delete it like a variable:

delete variable myArray["key1"]["key2"]

If you have your data saved in a custom property, you put the custom property into a variable, delete an element like above, and then set the custom property to the variable.

Best,

Mark