12.13 Undefining Arrays

12.13.1 Synopsis

undef (array [ ]);

12.13.2 Description

array is undefined; in other words Cows behaves as if it were never been defined. If you want to erase variable's content without undefining it, you can simply assign an empty string to each of its elements:

array [0] = "";
array [1] = "";
array [2] = "";
...

By doing so, if you later use array, Cows won't raise any warning.

Foreach loops (Section 16.2) represent a more convenient way to do the same thing:

foreach (element in array [ ]) {
  element = "";
}

12.13.3 Example

array [ ] = {
  "Fur used to turn heads,",
  "now it turns stomachs.",
  "-- Rue McClanahan"
};
print (array [0]);
print (array [1]);
print (array [2]);
undef (array [ ]);
print (array [0]);
print (array [1]);
print (array [2]);

This quotation is printed only once because of the undef statement:

Fur used to turn heads,
now it turns stomachs.
-- Rue McClanahan

This manual can be downloaded from http://www.g-cows.org/.