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

I have a list of hours I basically want to subtract 5 from. Why does this code not print the hour "1"?
#!/usr/bin/perl use Modern::Perl; my @f = qw(9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 0 1 2 3 4 5 7 8 +); foreach my $f (@f){ my $x = ($f-5)%24; say $x; }
Why does it output 23 hours:
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 0 2 3
And not 24? Where's the 1????? Or at least a blank newline?

Replies are listed 'Best First'.
Re: Convet UTC to Eastern Time Zone
by awohld (Hermit) on Nov 27, 2013 at 00:30 UTC
    If you add the 6 to:
    my @f = qw(9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 0 1 2 3 4 5 6 7 + 8 );
    Then you're in business!!!
      LOL. Good catch awohld. ++
      Not that I've never been guilty of such things. :)

      --Chris

      #!/usr/bin/perl -Tw
      use Perl::Always or die;
      my $perl_version = (5.12.5);
      print $perl_version;
Re: Convet UTC to Eastern Time Zone
by Laurent_R (Canon) on Nov 27, 2013 at 07:20 UTC

    About the 0 you've got, think about what is 24 modulus 24 (i.e. the remainder of the division of 24 by 24). And for the 1 missing, you would need a 6 in your input to get the 1 in the output, and you don't have it.

    Update: BTW, the difference between 0 and 24 is also a matter of cultural differences across nations. In many countries, the time one hour after 23 pm is 0 am, in others it is 24 am or pm. But 00:00 or 24:00 are in effect the same time.