Ronald J Kimball wrote:
>On Fri, Apr 26, 2002 at 09:51:11PM +0200, Mail WebOn AS wrote:
>> Was looking through the PGAS code and ran into these lines :
>> 
>> # Is there a better way to do this? Probably
>> my $day  = int($time_left/(60*60*24));
>> my $hour = int(($time_left%(60*60*24))/(60*60));
>> my $min  = int((($time_left%(60*60*24))%(60*60))/60);
>> my $sec  = int((($time_left%(60*60*24))%(60*60))%60);

I don't know if I'll ever get used to other people looking through 
my sometimes warty code.  I'm glad I kept that comment in there. 
:-)

>I'd observe that the repeated moduluses are redundant.  $time_left %
>(60*60*24) % (60*60) is equivalent to $time_left % (60*60), because 
60*60
>is a factor of 60*60*24.  int() is also redundant; modulus returns an
>integer by definition.
>
>my $day  = int($time_left/(60*60*24));
>my $hour = $time_left % (60*60*24);
>my $min  = $time_left % (60*60);
>my $sec  = $time_left % 60;

Other than $day, which is the same as mine, only $sec is correct 
(and a huge improvement over my disgustingly redundant mess).  $hour 
and $min will both contain seconds.  I used your observations, though,
and shortened my original $hour and $min to this:

my $day  = int($time_left/(60*60*24));
my $hour = int($time_left % (60*60*24)/(60*60));
my $min  = int(($time_left % (60*60))/60);
my $sec  = $time_left % 60;

It has been committed to CVS and will be in the next PGAS release.
Thanks!

--Dave






Reply via email to