Brian wrote:
John W. Krahn wrote:
Brian wrote:
This is what I'm using upto the code that is giving me a headache.

I know it's messy, but I have no training in PERL, I am trying to forward-engineer this cgi by back-engineering from html templates I created and which were chosen using $t->src

[ *SNIP* ]


################ whether or not leapyear
{
($myleap = 0 )
}
if ($Calend eq "b" ) {$myleap += 1}
if ($Calend eq "d" ) {$myleap += 1}
if ($Calend eq "f" ) {$myleap += 1}
if ($Calend eq "h" ) {$myleap += 1}

The usual way to calculate a leap year is:

sub is_leap_year {
    my $year = shift;
    return $year % 4 == 0 && $year % 100 != 0 || $year % 400 == 0
    }

I guess that % means 'wholly divisible by'

perldoc perlop

[ *SNIP* ]

    Binary "%" computes the modulus of two numbers.  Given integer
    operands $a and $b: If $b is positive, then "$a % $b" is $a minus
    the largest multiple of $b that is not greater than $a.  If $b is
    negative, then "$a % $b" is $a minus the smallest multiple of $b
    that is not less than $a (i.e. the result will be less than or equal
    to zero).  Note that when "use integer" is in scope, "%" gives you
    direct access to the modulus operator as implemented by your C
    compiler.  This operator is not as well defined for negative
    operands, but it will execute faster.


And presumably starts out as a 4 digit number, gets tested and overwritten by 0 or 1, 1 being true?

What starts out as a 4 digit number? What gets tested? What gets overwritten? You will have to be more specific on what you think is happening for me to either agree with you or correct you.


################ whether year starts on a Sunday
{
($mystart = 0 )
}
if ($Calend eq "a" || $Calend eq "b") {$mystart -= 0}
if ($Calend eq "c" || $Calend eq "d") {$mystart -= 1}
if ($Calend eq "e" || $Calend eq "f") {$mystart -= 2}
if ($Calend eq "g" || $Calend eq "h") {$mystart -= 3}

use Time::Local;

sub year_starts_sunday {
    my $year = shift;
    return !( gmtime timegm 0, 0, 12, 1, 0, $year - 1900 )[ 6 ]
    }


Oh oh oh, I think you think I am only working with the current year.

No, I do not think that. However using timegm() implies a certain upper and lower bound to the range of years that can correctly be calculated.



John
--
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to