grinder has asked for the wisdom of the Perl Monks concerning the following question:
#! /usr/local/bin/perl -l package P; sub new { use Time::HiRes 'time'; return bless { t => time }, 'P' } package main; print P->new->{t};
produce 1145538655.40264, and yet the following code (note the string eval)
#! /usr/local/bin/perl -l package P; sub new { eval "use Time::HiRes 'time'"; die $@ if $@; return bless { t => time }, 'P' } package main; print P->new->{t};
produce 1145538655 (that is, no fractional accuracy)? %INC does contain a Time::HiRes afterwards...
I have tried requireing and importing but that doesn't work either, and I'm at a bit of a loss. Basically, I'm just trying to attempt to load Time::HiRes on demand, and if it available, then I get improved time accuracy, and if it doesn't, well there's no harm done.
But as it stands, I never get improved accuracy, and I don't know what I'm missing.
Thanks for the clues (and I'll punch anyone who mumbles use strict :)
• another intruder with the mooring in the heart of the Perl
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Importing Time::HiRes::time at run-time (and failing)
by salva (Canon) on Apr 20, 2006 at 13:44 UTC | |
by grinder (Bishop) on Apr 20, 2006 at 15:10 UTC | |
by salva (Canon) on Apr 20, 2006 at 15:28 UTC | |
|
Re: Importing Time::HiRes::time at run-time (and failing)
by blazar (Canon) on Apr 20, 2006 at 13:37 UTC | |
|
Re: Importing Time::HiRes::time at run-time (and failing)
by Hue-Bond (Priest) on Apr 20, 2006 at 13:53 UTC |