On 4/17/09 Fri Apr 17, 2009 1:50 PM, "Brian" <[email protected]>
scribbled:
> Brian wrote:
>
> oops, should read......
>
> $Year_out = $Year_in;
>
> while ($Year_out > 100) {$Year_out -= 100;}
> if (($Year_out > 00) && ($Year_out <= 25)) {$string = $string1;}
> if (($Year_out > 25) && ($Year_out <= 50)) {$Year_out -=
> 25;$string = $string2;}
> if (($Year_out > 50) && ($Year_out <= 75)) {$Year_out -=
> 50;$string = $string3;}
> if (($Year_out > 75) && ($Year_out <= 100)) {$Year_out -=
> 75;$string = $string4;}
You are doing quite a few redundant tests here. Note that after your while
loop, $Year_out cannot be greater than 100. Also, if $Year_out is greater
than 25, it must be greater than 0. In addition, when you are done,
$Year_out will be between 0 and 25. Therefore, you can take the value modulo
25 and rearrange the tests to be a little more efficient (I am assuming that
$Year_out is always >= zero):
while ( $Year_out > 100 ) {
$Year_out -= 100;
}
if ( $Year_out > 75 ) {
$string = $string4;
}elsif ( $Year_out > 50 {
$string = $string3;
}elsif ( $Year_out > 25 ) {
$string = $string2;
}elsif ( $Year_out > 0 ) {
$string = $string1;
}
$Year_out = $Year_out % 25;
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/