String Processing

Hashes

In this lesson the student will learn how to:
    li>Know how to create and use hashes
  1. Know how extract the keys and values from a hash
  2. Know how to extract a single value from a hash
By the end of this lesson the student will be able to:

	Write an amino acid quiz script
	using a hash.

Protein Structure

Amino acids are the building blocks of proteins. Proteins, however, are not merely strings of amino acids. Their structure can be looked at from the following perspectives:

  1. Primary Structure - Amino acid sequence
  2. Secondary Structure - Local folds within a chain or the motifs formed by amino acids which are near to each other.
  3. Tertiary Structure - Overall shape of a polypeptide or the way it folds once local motifs have formed.
  4. Quarternary Structure - The way different polypeptides attach to one another to form functional complexes.

Hashes

#!/usr/bin/perl %ES = ( 'one' => 'uno', 'two' => 'dos', 'three' => 'tres', 'four' => 'quatro', 'five' => 'cinco', 'six' => 'seis' ); @eng = keys(%ES); @span = values(%ES); #not necessary in the order as shown above! print "ENGLISH: @eng\n"; print "SPANISH: @span\n"; foreach $item (keys ( %ES)){ print "$item --> $ES{$item}\n"; } #individual item: print "------\n"; print "one --> $ES{'one'}\n";
Take a look at the example above and the example below and make sure you understand how to access an item in a hash and note that there are two ways to initialize a hash. Also make sure that you figure out what the keys and values functions do. Note that each returns an array.
#!/usr/bin/perl %ah = ( "fred", 17, "wilma", 22, "dino", 5, "pebbles", 3); foreach $item (keys %ah){ print "$item --> $ah{$item}\n"; }

ASSIGNMENT:

Write a script which quizzes the user on the amino acid names and symbols. When presented with a symbol, the user must enter the name of the corresponding amino acid. The quiz script must use a hash and the amino acids must be presented in random order.