July 24, 2014
 
 
RSSRSS feed

Perl and the Y2k problem - page 4

Doomsayers everywhere

  • October 20, 1999
  • By Tom Christiansen
Now, what about Perl? Is Perl ``Year 2000 Compliant''? The answer is that Perl is every bit as Y2K compliant as is your pencil; no more, and no less. Does that comfort you? It shouldn't. Just as you can commit Y2K transgressions with your pencil, so too you can do so with Perl--or with any other tool, for that matter. You don't really even have to go very far out of your way to do so; witness the demonstration of the perfectly compliant cal program provided above.

The date and time functions supplied with Perl are the gmtime() and localtime() functions, which are derived from their namesakes in the C programming language. These supply adequate information to determine the year well beyond 2000. 2038 is when trouble strikes, but only for those of us then still stuck on 32-bit machines, a somewhat unlikely albeit admittedly not entirely unthinkable situation.

The year returned by these functions (when used in list context) is, contrary to popular misconception, not by definition a two-digit year. Rather, it merely happens to be such right now. What it actually is, is the current year minus one thousand nine hundred. For years between 1900 and 1999 this happens to be a 2-digit decimal number, but that's not going to last long. To avoid the year 2000 problem, simply do not treat the year as a 2-digit number. Easy to say, and easy to break. Imagine that you want find out what the year appears to be in five years, so you write code like this.

    use Time::localtime;
    $then = time() + ( 60 * 60 * 24 * 365 * 5 );  # 5 years from now
    $that_year = localtime($then)) -> year;

    printf("It shall be 19%d\n", $that_year);           # WRONG! 19103
    printf("It shall be %d\n", 1900 + $that_year);      # right:  2003

As you see, in the wrong hands, even a nominally year 2000 compliant tool such as Perl or cal can be misused by the underclued or simply the forgetful.

Executive summary from TPI, The Perl Institute:

Perl has no warranty, and TPI does not support Perl. Furthermore, Perl is a language, and languages can be misused in many ways. But that's the responsibility of the programmer and the user, not of the many creators of Perl. Nevertheless, as spokes-organization for the Perl freeware movement, we feel compelled to point out that Perl is every bit as Y2K compliant as the C language upon which its interfaces are based, and in which the Perl compiler and interpreter are themselves written. That is, the interfaces giving access to date information in Perl, when used as designed, are Y2K compliant in every sense of that word.

If that makes your lawyers or managers happy, well, good for them. You still have a lot to worry about.

If you can think of any way to make this message more helpful, please let me know. I apologize in advance if this message comes off sounding unkind to you; it wasn't meant to be. I'm honestly just trying to help to make the Net a better place for all of us.

Sitemap | Contact Us