in reply to Only

I would use something like the following:
if ( eval { require Time::Hires } ) { # The require was successful } else { # It was unsuccessful }
The eval with braces will trap the die if Time::Hires is not on your system.

Cheers,
Ovid

Update: Whups! Since I hadn't used Time::Hires before, I wasn't aware of what it does internally. I suspect that autark's correction below is appropriate.

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re: (Ovid - try eval)Re: Only
by autark (Friar) on Dec 11, 2000 at 22:48 UTC
    But the function time() from Time::HiRes will not be imported. To make this binding between &main::time and &Time::HiRes::time we have to this at compile time:
    BEGIN { eval { require Time::HiRes; import Time::HiRes qw(time) }; if($@) { warn "Unable to import Time::HiRes\n" }; }
    Without the BEGIN, the binding of time to the correct function would not happen:
    eval { require Time::HiRes; import Time::HiRes qw(time) }; print time()
    Would produce f.exs: 976556706. While
    BEGIN { eval { require Time::HiRes; import Time::HiRes qw(time) }; } print time()
    Would produce the correct time using the Time::HiRes::time function: 976556789.394509.

    Autark.