Arrays and Hashes
An array is a collection of numbers or strings that can be indexed using a numeric subscript. Consider the following NASL script:
myarray=make_list(1,"two");
display("The value of the first item is ",myarray[0]," \n");
display("The value of the second item is ",myarray[1]," \n");The script displays the following when executed:
The value of the first item is 1 The value of the second item is two
Notice that the array subscripts begin at 0, and that is why the
first element is obtained using the [0] subscript.
Like
arrays,
hashes are also collections of numbers or
strings. However, elements in hashes have a key value associated
with them that can be used to obtain the element. You can use the
make_array( )
function call to define a hash.
Because every element must have an associated key value, the function
call requires an even number of arguments. The following is a
definition of a hash that contains port numbers for the Telnet
protocol (port 23) and HTTP (port 80):
myports=make_array('telnet',23,'http',80);Now, myports['telnet'] gives you the value of
23, while myports['http']
evaluates to 80.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access