in reply to Re^2: Interesting behavior in eval block
in thread Interesting behavior in eval block
Your "trick" doesn't work. You're just duplicating the work the implicit import in use already does. Like I said in my original post, it's *when* it happens that's important.
You have the right idea, but it needs to be done at compile-time. Fortunately, it's very simple since Perl already provides a means of declaring a function that's to be defined at a later time.
sub gettimeofday(); # Eventually. eval "use Time::HiRes qw( gettimeofday ); 1" or die "Unable to load Time::HiRes: $@\n"; print(gettimeofday);
The parens in "sub gettimeofday();" are only there because Time::HiRes declares the function using that prototype.
|
|---|