www.perl.com
Perl Programming
Hashes
  • May be sliced
    • A slice is an array of the hash's values
    • Take a hash slice with @hash{@keys}
    • $hash{cow} is a scalar, that is, a single value
    • @hash{cow} is an array, containing a single scalar
    • Hashes always begin with %

        my %sounds = (cow   => "moooo",
                      duck  => "quack",
                      horse => "whinny",
                      sheep => "baa",
                      hen   => "cluck",
                      pig   => "oink");

        my @barnyard_sounds = @sounds{"horse", "hen", "pig"};
        print "I heard the following in the barnyard: @barnyard_sounds\n";
      

        Output:
        I heard the following in the barnyard: whinny cluck oink
      
http://stuff.mit.edu/iap/perl/