March 19 2012
Catch stupid mistakes when mucking with years, like Y2K bugs NO, PERL DOES NOT HAVE A Y2K BUG! but alot of people seem determined to add it. Perl, and most other languges through various historical reasons, like to return years in the form of the number of years since 1900. This has led to the false assumption that its actually returning the last two Digits of the current year (1999 => 99) and the mistaken assumption that you can set the current year as "19$year".This is a Y2K bug, the honor is not just given to COBOL progrmamers.Bugs of this nature can easily be detected (most of the time) by an automated process. This is it.When the D'oh::Year module is used, it provides special versions of localtime() and gmtime() which return a rigged value for the year. When used properly (usually 1900 + $year) you'll notice no difference. But when used for EVIL it will die with a message about misuse of the year.The following things are Naughty (where $year is from gmtime() or localtime()): "19$year", 19.$year "20$year", 20.$year "200$year", 200.$year $year -= 100, $year = $year - 100;THE FOLLOWING ARE THE CORRECT WAYS TO MANIPULATE THE DATE Take note, please. $year += 1900; # Get the complete year. $year %= 100; # Get the last two digits of the year. # ie "01" in 2001 and "99" in 1999SYNOPSIS use D'oh::Year; ($year) = (localtime); print "We're going to party like its 19$year"; # No you're not. print "Welcome to the year 20$year!"; # Sorry, Buck.