Next Tricks of the Wizards 151

Overloading: Y2K Detection Example

        package y2k;
        ...
        sub to_num {
          my ($year) = @_;
          return $year->{YEAR};
        }
        sub concat {
          my ($y2k, $s, $rev) = @_;
          carp("Detected possible Y2K problem");
          my $year = sprintf("%02d", $y2k->{YEAR} % 100);
          $rev ? $s . $year : $year . $s;
        }


Next Copyright © 2003 M. J. Dominus