Other important variables are reserved:
Another type is the array, an array is a numbered list of scalars. The array is identified by the at sign ( @ ) in the same ways that dollar sign ( $ ) indicates the scale.
All arrays are numbered from 0: the first element take index 0, the second one and so on. The elements are placed in an array as a list separated by commas and parentheses. The n-th element of the generic array @array is defined as $array[n] . In this case, you use $ instead of @ because it refers to a scalar, not the entire array.
A few examples follow. Let us first define a variable $var :
$ Var = 1;
Let us now see how to define an array. An element is defined with a value of $var :
@ Array = ("bla", 34 "uff", $ var);
Now we take the second value of the array and assign the variable $second, renumbered 34 :
$ Seconds = $ array [1];
Now we define a new array @eek , that takes a subset of the elements of @array , as defined above:
Eek @ = @ array [0, 2];
@eek becomes ("bla", "uff") , since it takes the first and third value of @array .
Let's see how to connect two arrays
Urka @ = (@ array, @ eek);
This is NOT an array of arrays, since arrays are always an array of scalars. What happens is that all values of @array and @eek are copied @urka, which contains ("bla", 34, "uff", 1, "bla", "uff").
There are functions that operate on arrays, adding elements to the end, remove, removing those that satisfy a given condition, orders etc.. To find the cardinality of an array, you use the hash sign ( # ) after the at sign. For example, the expression @#array is the number of elements of @array minus one. To empty the array, this is taken as -1.
@ Array = ("bla" "bla" "bla" "bla");
print $ # array, "\ n";
Note: The pound sign ( # ) in this case ( $#array ) does not introduce a comment.
Bookmarks