Is leap year subroutine : date time « Data Type « Perl






Is leap year subroutine

  

$my_year = 2000;

if ( is_leap_year( $my_year ) ) {  
   print "$my_year is a leap year\n";
}
else {
   print "$my_year is not a leap year";
}

sub is_leap_year {        
   my $year = shift(@_);          # Shift off the year from the parameter list, @_
   return ((($year % 4 == 0) && ($year % 100 != 0)) ||
   ($year % 400 == 0)) ? 1 : 0;   # What is returned from the function
}

   
    
  








Related examples in the same category

1.To extract the current date by using time and localtime
2.Set the value of localtime to a scalar variable, you'll get a typical UNIX-style time
3.scalar(localtime(time()))
4.Splitting Time
5.Create new time based on the value from localtime
6.Print out the current time in standard time
7.Execute date command and get user input
8.Time of Day
9.Switch Time
10.Converting Time
11.Splitting Local Time
12.localtime converts a time into the local time.
13.gmtime function converts a time value into Greenwich Mean Time