Question 3

The hash slice and the => part turned out to be the most difficult in
this section.

# part a -- using ..
@day_nums = (1 .. 7);

# part b -- no explicit use of quotes to assign array of strings
@day_strings = qw(mon. tue. wed. thur. fri. sat. sun.);

# part c -- use one array as a list of keys and another as a list of
#           values and create a hash (hash slice)
@days1{@day_nums} = @day_strings;
# note $days1{@day_nums} = @day_strings is not correct

# part d -- create a hash using literals and =>
%days2 = (
  1 => "mon.",
  2 => "tue.",
  3 => "wed.",
  4 => "thur.",
  5 => "fri.",
  6 => "sat.",
  7 => "sun."
	 );
# note that => automatically quotes the literal before it, but
# not any string after it

# part e -- use foreach to print values of the hash
foreach $value (values(%days)) {
    print("$value\n");
}
# or
foreach $key (keys(%days)) {
    print("$days{$key}\n");
}

# part f -- use the each function to iterate through;
#           capitalize first letter of each value
while (($key,$value) = each(%days)) {
    print("\u$value\n");
}


Louis Ziantz
3/26/1998