cheech has asked for the wisdom of the Perl Monks concerning the following question:
Is there a better way for me to handle these exceptions?
Thanks,
Dave
# First, the current date is determined use Date::Simple::D8 (':all'); my $today = Date::Simple::D8->today(); my $end_date = $today; # Prompt user for start date and verify it print "Please enter the collection start date (YYYYMMDD): "; my $start_date = <>; chomp ($start_date); while ($start_date !~ (/\d\d\d\d\d\d\d\d/)) { print "ERROR: Invalid format! Start date (YYYYMMDD): "; $start_date = <>; chomp ($start_date); } while ($start_date < 18960101) { print "ERROR: Data prior to 18960101 is not available! Start date +(YYYYMMDD): "; $start_date = <>; chomp ($start_date); } while ($start_date > "$today") { print "ERROR: Start date is in the future! Start date (YYYYMMDD): +"; $start_date = <>; chomp ($start_date); } print "Thank you, collection will begin with $start_date\n"; # Ask user if most recent available date should be used as end date print "Would you like to collect through the most recent available dat +e? (y/n): "; my $ans = <>; chomp ($ans); if ($ans eq "n" || $ans eq "N") { print "Please enter the collection end date (YYYYMMDD): "; my $end_date = <>; chomp ($end_date); while ($end_date !~ (/\d\d\d\d\d\d\d\d/)) { print "ERROR: Invalid format! End date (YYYYMMDD): "; $end_date = <>; chomp ($end_date); } while ($end_date < 18960101) { print "ERROR: Data prior to 18960101 is not available! End dat +e (YYYYMMDD): "; $end_date = <>; chomp ($end_date); } while ($end_date > "$today") { print "ERROR: End date is in the future! End date (YYYYMMDD): +"; $end_date = <>; chomp ($end_date); } print "Thank you, collection will end with $end_date\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Handling User Input
by almut (Canon) on Nov 25, 2009 at 20:13 UTC | |
|
Re: Handling User Input
by jethro (Monsignor) on Nov 25, 2009 at 20:54 UTC | |
|
Re: Handling User Input
by Marshall (Canon) on Nov 26, 2009 at 05:05 UTC | |
|
Re: Handling User Input
by holli (Abbot) on Nov 26, 2009 at 16:21 UTC |