#!/usr/local/bin/perl
print "Associative arrays\n";
$month_days{"January"}=31;
$month_days{"February"}=28;
$month_days{"March"}=31;
$month_days{"April"}=30;
$month_days{"May"}=31;
$month_days{"June"}=30;
$month_days{"July"}=31;
$month_days{"August"}=31;
$month_days{"September"}=30;
$month_days{"October"}=31;
$month_days{"November"}=30;
$month_days{"December"}=31;
#
$march_days=$month_days{"March"};
print "Days in March: $march_days\n";
$spring_days=$month_days{"March"}+$month_days{"April"}+$month_days{"May"};
print "$spring_days spring days\n";
$month_days{"March"}=100;
$march_days=$month_days{"March"};
print "Days in March: $march_days\n";
#
%file_lines=('f1.txt' => 30, 'f2.txt' => 20, 'f3.txt' => 10);
$x=$file_lines{"f1.txt"};
print "$x lines in f1.txt\n";
@files=keys(%file_lines);
print "The files are @files\n";
@lines=values(%file_lines);
print "The number of lines in each file: @lines\n"; 
$total=0;
while (($f,$l)=each(%file_lines)) {
  $total+=$l;
}
print "Total number of lines $total \n";
#
if (open(inh,"<phonedb.txt")) {
   @db=<inh>;
   $ldb=$#db + 1;
   for $i (0..$#db) {
     ($fname, $lname, $phones)=$db[$i];
     $name=$lname.' '.$fname; 
     $dbnew{$name}=$phones;
   }
   while (($name,$phones)=each(%dbnew)) {
      print "$name $phones\n";
   }
   close(inh);
}
else {
    print "Error opening phonedb.txt \n";
}
