#!/usr/bin/perl

use strict;
my %lastname;
my (%hash2,%hash3,@ar1);  # Something new !!

# 2 ways to initialize hashes

%lastname=( "Bill","Smith","Joe","Davis","Sue","Harris");
%hash2=( Dave=>"Jones", Bob=>"Smith",Dave=>"qqqq");
%payrate( Ed=>10.59 , Joe=>7.75,  Sue=> 12.56);


# despite warnings in book, hashes do not need an even number of elements


%hash2=( "Bill","Smith","Joe","Davis","Sue","Harris","Harry");
@ar1=qw;
%hash3=@ar1;


# order of output is not quaranteed
print %lastname;


# figure this one out!!
my $a;
$a=3+%lastname;
print "A is $a\n";

# OK. So what are they good for ?????

my $who="Sue";
print "Sue's last name is ",$lastname{$who},"\n";

#quiz question: what happens if we try to look up the last name for Harry 
# in hash1 ??

#easy to add to a hash. Note no quotes on the key!!

$lastname{Rosco} = "Adams";

print %lastname,"\n";
print "Rosco's last name is ",$lastname{Rosco},"\n";

#easy to change
$lastname{Bill}="o'Neill";
print "Bill's last name is ",$lastname{Bill},"\n";

print %lastname,"\n";

# Yes. You can delete from a hash

delete $lastname{Bill};
print %lastname,"\n";


# the keys operator . Prints the keys of a hash

print keys %lastname,"\n";       

# the values operator. Quess what it does

print values %lastname,"\n";

#printing out an entire hash nicely

my $keyValue;

foreach $keyValue (keys %lastname)
{
	print $keyValue, " has a last name ",$lastname{$keyValue},"\n";
}