quest4tech.net

 

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";
    }

To add an entry or comment on the article, please fill in the comments form


Return to Top

Main Index


(c) Created by B V Wood.

  Main Index
  Comments

UK SPONSERS

 
USA SPONSERS