Example three - associative arrays
#Example three - associative array variables and print.
# the associative array %a is defined by its elements using
# the scalar $a with curled brackets {} to define both key and value.
#
# by Al Bento
$a = "this is example";
$b = 3;
$a{"field1"} = $a;
$a{"field2"} = $b;
print "$a{field1} number $a{field2}\n";
# here is an example of transferring the values of %a to @a
@a = %a;
# see what comes out as output of printing all elements of
# the array @a
print "$a[0] = $a[1] ; $a[2] = $a[3]\n";
download the script
This page is maintained by Al Bento
who can be reached at abento@ubmail.ubalt.edu. This page was last updated on June 15, 1997. Although we will attempt to keep this information accurate, we can not guarantee the accuracy of the information provided.