arrays
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
| — | arrays [2007/07/10 20:02] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ======Karll' | ||
| + | |||
| + | You are probably familiar with the client' | ||
| + | like perl's hash tables, and store a simple scalar value into a named variable. | ||
| + | You can stick multiple values into a variable, but they require that you do | ||
| + | your own encoding, and that's always hard to get correct. | ||
| + | |||
| + | The client also supports //Karll Arrays// which are multi-variable arrays. | ||
| + | Each Karll array has a name and can store an unlimited number of scalar values, | ||
| + | which are indexed with a number, just like a regular perl array. | ||
| + | |||
| + | Arrays are indexed sequentially, | ||
| + | created when item 0 in a previously nonexistent array is defined: | ||
| + | |||
| + | | ||
| + | |||
| + | This sets element 0 of array " | ||
| + | Further items may be added sequentially; | ||
| + | must be 1, and anything above 1 will result in an error. | ||
| + | elements may be freely overwritten: | ||
| + | |||
| + | | ||
| + | |||
| + | Now element 0 of array " | ||
| + | may be deleted from the array. | ||
| + | in the array (the one with the highest item number), all items after it | ||
| + | are shifted down by one; this prevents an array from having " | ||
| + | |||
| + | | ||
| + | | ||
| + | |||
| + | This first adds a new element, then deletes the first element. | ||
| + | is an array that is one item in size. Item 1 become item 0. | ||
| + | |||
| + | One powerful feature of arrays not present in hashes is the ability to | ||
| + | search through the array elements for random data. The simplest methods are | ||
| + | probably already familiar to you. They operate in much the same manner as | ||
| + | the $[[match]]() and $[[rmatch]]() functions. | ||
| + | Given that some array " | ||
| + | 0): | ||
| + | |||
| + | | ||
| + | | ||
| + | |||
| + | One could then use $[[matchitem]]() to find the element that best matches an | ||
| + | arbitrary input pattern. | ||
| + | patterns, $[[rmatchitem]]() could find which one best matched some non-wildcard | ||
| + | string. | ||
| + | |||
| + | The most powerful searching feature is $[[finditem]](). | ||
| + | functions, it runs through an array looking for an item that matches the | ||
| + | input string. | ||
| + | case. This function uses a binary search algorithm, and is quite fast. | ||
| + | |||
| + | The other feature of note is an array' | ||
| + | All array elements have an item number (the order in which it was added) | ||
| + | and an index number (its sorted position in the array). | ||
| + | are fetched by item number with $[[getitem]]() and by index | ||
| + | number with $[[igetitem]](). The result is that you can | ||
| + | sequentially print out an array' | ||
| + | $[[igetitem]](), | ||
| + | |||
| + | There is more to these arrays than is presented here. Each function used to | ||
| + | access and manipulate them is fully documented in Section 6 of these help | ||
| + | files. | ||
| + | |||
arrays.txt · Last modified: 2007/07/10 20:02 by 127.0.0.1
