Examples of using the hash data structure in Perl |
Create a hash:-
%exampleHash = ( "Mars" => "3", "Jupiter" => "4", "Saturn" => "7" );
Display the key associated with the value Jupiter:-
print "Key for Jupiter is ", $exampleHash{"Jupiter"},"\n";
Display all the keys and values in %exampleHash:-
while (($key, $value) = each %exampleHash) {
print "($key, $value)\n";
}
Check if the key for Saturn is in %exampleHash
if (exists $exampleHash{"Saturn"}) {
print "Found Saturn\n";
} else {
print "Did not find Saturn\n";
}
|
|
Main Index
Comments
UK SPONSERS
USA SPONSERS
|