On Thu, Jul 26, 2001 at 10:26:45AM -0700, Wagner-David wrote:
I'm not sure if you wanted a code review for this, but one follows.
> #!perl -w
>
> use Time::Local;
>
> my @DateUse = ();
There's no need to initialize @DateUse like this, arrays start empty. You
should move this into the while loop to obviate the need to clear it each
time.
> while ( 1 ) {
my @DateUse;
> printf "Please enter date to check: ";
> chomp(my $Dates = <STDIN>);
> last if ($Dates =~ /^ex/i );
>
> if ( length($Dates) < 6 || $Dates !~
> /^(\d{1,2})[^0-9]{0,1}(\d{1,2})[^0-9]{0,1}(\d{1,4})/ ) {
I'd use:
/^(\d\d?) \D? (\d\d?) \D? (\d{1,4})$/x
and omit the length check.
> printf "Expecting some form of a date in format:\n";
> printf "mm/dd/yy, mmddyy, m/d/yy, m/d/yyyy\n";
> printf "You entered: <$Dates>\n";
> printf "Please enter correct data\n";
> next;
> }
> undef @DateUse;
This is unnecessary when @DateUse is lexical to the while loop.
> push(@DateUse,($1,$2,$3));
> printf "%d\n", scalar(@DateUse);
>
> if ( ! (scalar(@DateUse) and ! (scalar(@DateUse) % 3) ) ) {
I'm not sure why you're even doing this check, the regex already verified
the date was in a valid format.
Readability could be improved here; you have two negated checks, a
useless use of scalar, and you're checking for a multiple of three when
there can only be three elements, no more.
unless (@DateUse == 3) {
> die "Expecting groups of 3 for date calculations:$!";
> }
>
> for(my $MyId=0;$MyId<scalar(@DateUse);$MyId+=3) {
Here you continue the multiple-of-three bit with @DateUse. Is this some
sort of legacy holdover?
> my $t1 =
> timelocal(0,0,12,$DateUse[$MyId+1],$DateUse[$MyId]-1,$DateUse[$MyId+2]);
> printf "t1: %9d\n", $t1,;
> my $MyTime1 = localtime($t1);
> printf "LocalTime1: %-s\n", $MyTime1;
> my @MyTimeInfo = localtime($t1);
> if ( length($DateUse[2]) > 3 ) {
> $MyTimeInfo[5]+=1900;
> }elsif ( length($DateUse[2]) < 3 ) {
> $MyTimeInfo[5] = $MyTimeInfo[5] % 100;
> }
This seems odd to me. You're correcting localtime() output based on its
input? You should probably correct @DateUse before handing it off to
timelocal(). It would simplify this code and make it more understandable,
especially considering the obscure array indexes being bandied about.
> # MyTimeInfo [0] = Seconds
> # [1] = Minutes
> # [2] = Hours
> # [3] = Day of month
> # [4] = Month minus 1
> # [5] = Year (from 1900)
> # [6] = Day of Week(Mon=1 thru Sun=7);
> # [7] = Day of year
> # [8] = Day light Savings(0: off 1: On)
> #
> if ( $DateUse[0] != $MyTimeInfo[4]+1 or $DateUse[1] != $MyTimeInfo[3]
> or
> $DateUse[2] != $MyTimeInfo[5] ) {
> printf "Did not come back with the same date inputted:\n";
> printf "Month: I/P: %2d Gen: %2d\n", $DateUse[0],
> $MyTimeInfo[4]+1;
> printf "Day : I/P: %2d Gen: %2d\n", $DateUse[1], $MyTimeInfo[3];
> printf "Year : I/P: %2d Gen: %2d\n", $DateUse[2], $MyTimeInfo[5];
> }
> }
> }
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]