#!/usr/bin/perl

use strict;


main();

sub main {

    #initialize a hash with one key/value pair
    my %hash->{'apple'} = "orange";

    #add more key/value pairs to the hash
    %hash->{'1'} = "2";
    %hash->{'foo'} = "bar";
    %hash->{'georgia'} = "peach";

    print "Printing the hash\n";
    _print_hash(%hash);  #printing uses the keys function.
    
    print "\n\n----------\n Use some other hash functions\n";
    #delete a specific key
    delete($hash{'georgia'});

    print "\n\nAfter delete print the hash\n";
    _print_hash(%hash);
    print "\nnotice that 'georgia->peach' is now gone\n\n";
    print "test if 'foo' is a key\n";
    if (exists($hash{'foo'})) {
	print "\tfoo IS a key!\n";
    } else {
	print "\tfoo IS NOT a key\n";
    }
    print "\n";

    print "test if 'far' is a key\n";
    if (exists($hash{'far'})) {
	print "\tfar IS a key!\n";
    } else {
	print "\tfar IS NOT a key\n";
    }

    print "\n\n-------------\nGet all hash values into an array....\n";
    my @values = values(%hash);
    print "Values: \'@values\'\n\n";
	

}


sub _print_hash {
    my (%hash) = @_;

    foreach my $key (keys(%hash)) {
	print "$key ...\'$hash{$key}\'\n";
    }

    

}

