http://qs321.pair.com?node_id=1131293

Aldebaran has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I'm working out the details on my latest script and have hit a snag with results I don't understand from the modulo operator. I could work around it with ordinary division and truncation, but I'm stubborn:

sub second_to_string{ use warnings; use strict; use 5.010; my $seconds = shift; say "seconds are $seconds"; my $hours = $seconds % 3600; say "hours are $hours"; my $remainder = $seconds - $hours *3600; say "remainder is $remainder"; my $return = join('', $hours, 'h '); return $return; }

Output:

seconds are 34640 hours are 2240 remainder is -8029360 equal_ra is 2240h

The correct answer for hours is 9, and the remainder should not be negative. Thanks for your comment.