You don't need to overload an inbuilt function IF you define one of the same name and call it with the ampersand prepended, i.e. &time will execute a user-defined subroutine named time if it exists. Otherwise, you can check out dchetlin's tutorial Overloading '=' for some info on how to overload inbuilt functions.
As to the first problem: you can wrap require Time::Hires in an eval inside a BEGIN block, and if that eval fails, print a warning (if appropriate) and set a flag that tells your program to use the internally defined routine. If the eval succeeds, call import Time::Hires and you'll have the symbols imported.
#!/usr/bin/perl -w
use strict;
use vars '$internal';
BEGIN: {
eval "require Time::Hires";
if ($@) { # if it failed
print "Can't load Time::Hires, falling back to own routines\
+n";
$internal =1;
} else {
import Time::Hires;
$internal = 0;
}
}
HTH,
Philosophy can be made out of anything. Or less -- Jerry A. Fodor |