Powered by GeSHi

Source code for week.pl

(view source code of week.pl as plain text)

  1. #! perl
  2.  
  3. # Week.pl,  Version 2.00
  4. # Display week number using Perl
  5. # Written by Rob van der Woude
  6. # http://www.robvanderwoude.com
  7.  
  8. # Parse time string
  9. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  10.  
  11. # Calculate number of full weeks this year
  12. $week = int( ( $yday + 1 - $wday ) / 7 );
  13.  
  14. # Add 1 if today isn't Saturday
  15. if ($wday < 6) {
  16. 	$week = $week + 1
  17. }
  18.  
  19. # Display the result
  20. print "Week $week\n";
  21.