See whether you can produce a pattern to match a standard time format. All
the following should be acceptable: 12:00am, 5:00pm, 8:30AM. These should probably not be accepted: 3:00,2:60am, 99:00am, 3:0pm.
####
#!/usr/bin/perl -w
use strict;
use warnings;
print "Type in the current time!\n";
my $input = ;
while($input)
{
if($input =~ m/(\d)*(\d):(\d)(\d)(\w)(\w)/ | $input =~ m/(\d)*(\d):(\d)(\d)(\s)(\w)(\w)/)
{
if($1 > 1 || $2 > 2 || $3 > 6)
{
print "That is not a valid time!\n";
print "Type the time again.\n";
$input = ;
}
else
{
print "That is a valid time!\n";
$input = 0;
}
}
else
{
print "Please be more specific.\n";
$input = ;
}
}
####
Last login: Thu Aug 18 11:28:44 on ttys000
youngs-mac-mini:~ fenimore$ cd ~/Documents
youngs-mac-mini:Documents fenimore$ perl TimeChecker.pl
Type in the current time!
4:90
Please be more specific.
4:30AM
Use of uninitialized value $1 in numeric gt (>) at TimeChecker.pl line 13, line 2.
That is not a valid time!
Type the time again.
12:30PM
That is a valid time!
youngs-mac-mini:Documents fenimore$
####
if($1 > 1 || $2 > 2 || $3 > 6)