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
In reply to Re: Only
by arturo
in thread Only
by rrwo
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.