#!/usr/bin/perl -w

# assignment #7

#----------------------------------------------------------------------

$datafile = '/mnt/homes/CLASSES/CIS2279/LAB07/sunriseset.txt';

#Opens the file /mnt/homes/CLASSES/CIS2279/LAB07/sunriseset.txt for reading.
open(DF, "<$datafile") || die "cannot open file: $!";

# From the data found in the file, creates hashes to store several values 
# using the date as the common key. The values should be sunrise time and 
# sunset time. For example, this should be arranged so that $sunrise{'Jan 04'} 
# will contain the value "0725".

$junk = <DF>; # strip the header
$junk = <DF>; # strip the header

while($line = <DF>) {
    chomp($line);
    @ldata = split(/\s+/, $line);
    $date = "$ldata[0] $ldata[1]";
    $sunrise{$date} = $ldata[2];
    $sunset{$date} = $ldata[3];
}

# Once the hashes are created, the script will prompt the user to enter a 
# date to display. 
print "Please enter a date (ex: Jan 01): ";
chomp($ans=<STDIN>);

# When the user has provided the date, the script will then print out the 
# sunrise time and the sunset time using some descriptive text.
print "Sunrise and sunset for $ans:\n\tSunrise: $sunrise{$ans}\n\tSunset: $sunset{$ans}\n";

exit;