Scalars, Arrays, and Hashes
-
Hashes are new. Often called an associative array.
-
A collection of scalars in pairs. Like an array, but instead of having
a number represent the element index in an array, another scalar
does the job.
-
The first element is the key, the second element is the value.
-
Hashes start with %. Think of the duplicate 'o' as the key and value.
-
%classInfo = ("university", "UC", "college", "CECE", "building", "Sander
Hall", "classroom", "L222");
-
Accessing hashes is a little different as well. To get the value
for a key, the syntax is $hashname{'keyvalue'}
-
Example: http://homepages.uc.edu/cgi-bin/cgiwrap/jonesbr/simpleperl4.pl
%classInfo = ("university", "UC", "college", "CECE", "building", "Sander
Hall",
"classroom", "L222");
print "<br>University: ";
print $classInfo{'university'};
print "<br>College: ";
print $classInfo{'college'};
print "<br>Building: ";
print $classInfo{'building'};
print "<br>Classroom: ";
(etc.)
Operators and Functions
Home