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'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;
> 

This is incorrect.  Your $min value reports the number of seconds into
this hour and your $hour value reports the number of seconds into this
day.  Personally, I think the original version was fine.  But for
completeness, here's my excessively formatted contribution:

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

Chris Dolan

Reply via email to