#!/usr/bin/perl -w
######################
#
# read-and-report.pl
#
# Read in names and ages from the terminal.
# Report various properties from the stored data.
#
# Here's what running the program should look like.
# The lines starting with ">" are output by the computer;
# the others are typed by the user.
#
#   > Read and Report (version 0.2)
#   > What would you like to do ? ( input, summarize, list, clear, quit )
#   Go fly a kite.
#   >   Oops - I don't know how to '$choice'.
#   > What would you like to do ? ( input, summarize, list, clear, quit )
#   input
#   >   Enter a name. (Or a blank line to go back to the main menu.)
#   John Smith
#   >   How old is 'John Smith'?
#   32
#   >   Enter a name. (Or a blank line to go back to the main menu.)
#   Jane Doe
#   > How old is 'Jane Doe'?
#   82
#   >   Enter a name. (Or a blank line to go back to the main menu.)
#   Ducky
#   >   How old is 'Ducky'?
#   9
#   >   Enter a name. (Or a blank line to go back to the main menu.)
# 
#   > What would you like to do ? ( input, summarize, list, clear, quit )
#   summarize
#   >     There are 2 people in the list.
#   >     The oldest is Jane Doe, 82.
#   >     The youngest is Ducky, 9.
#   >     Their average age is 41.
#   > What would you like to do ? ( input, summarize, list, clear, quit )
#   list 
#   >   List all people older than what age?
#   20
#   >   The people older than 20 are
#   >     John Smith
#   >     Jane Doe
#   > What would you like to do ? ( input, summarize, list, clear, quit )
#   clear
#   >   List cleared.
#   > What would you like to do ? ( input, summarize, list, clear, quit )
#   summarize
#   >   The list is empty.
#   > What would you like to do ? ( input, summarize, list, clear, quit )
#   quit
#   > Bye.
#
# Version history
#
#   * 0.1_jm  partial program outline created; rest left as a class exercise.
#             Jim Mahoney, Sep 15 2003
#
######################
use strict;
my $VERSION = "0.1_jm";    # Change this to a higher number with your initials.
my $DEBUG = 1;             # 1 => print debugging diagnostics; 0 => don't.

print "Read and Report (version $VERSION). \n\n";

# Store the ( name => age) data in this hash.
# For example, 
#     $name_age_data{'Belgarath the Sorcerer'} = 7024;
my %name_age_data;

my $is_running = 1;
while ($is_running) {

  # Ask user what to do, and read in the choice.
  print "> What would you like to do ? ";
  print "( input, summarize, list, clear, quit )\n";
  my $choice = <>;            # Read in one line from the terminal.
  chomp($choice);             # Remove the carriage return.

  # Do different things depending on the user's choice:

  #  -- input --
  if ($choice eq 'input'){
    print "   - DEBUG - doing 'input'\n" if $DEBUG;
    # ... add your code here.
  }

  #  -- summarize --
  # ... add your code here.

  #  -- list --
  # ... add your code here.

  #  -- clear --
  # ... add your code here.

  #  -- quit --
  elsif ($choice eq 'quit'){
    $is_running = 0;
  }

  #  -- complain if the choice wasn't understood --
  else {
    print ">   Oops - I don't know how to '$choice'.\n";
  }

}
print "> Bye.\n";
