Next Tricks of the Wizards 147

Overloading: Bizarre Example

        (..., $year, ...) = localtime(...);
        $q =  "$mon/$day/$year";                            # wrong
        $q =  "$mon/$day/" . sprintf('%02d', $year % 100);  # RIGHT
        print "The year is 19$year.\n";                     # wrong
        print "The year is 19" . $year . ".\n";             # wrong
        print "The year is ", 1900+$year, ".\n";            # RIGHT


Next Copyright © 2003 M. J. Dominus