in reply to runtime "use" statements via string eval
Well, I can't say whether or not it's completely ideal, but I've started using something like this to ensure that I've got all the modules I need:
#!/usr/bin/perl -wT use strict; $|++; eval( "use MIME::Lite;" ); die "Module Configuration Error: $@" if $@; # and so on.
Since I'm writing scripts for servers that I don't have have access to, I'm forced to test them on my personal resources, get them working, and then toss them into the Black Hole known as "Security Testing" in the company I work for.
Personally, I like being able to tell the "experts" that they need to "tail their error log" in order to tell me what what wrong. *grin*
A recent check via CB seemed to think this was an okay approach. As always, YMMV...
Update: In reply to geektron's reply below:
Ah, I get you. Yeah, that feels weird. To my mind, you should localize your uses and your uses/requires into a configuration section before doing any work. If it's gonna fail, get it to do so before you waste any time...unless you have a problem with people, like, y'know, deleting modules from underneath you. (And if that's going on, well, friend, you've got more issues than concurrency ones, if you know what I mean.)
I spent about an hour poring over various perldoc entries and the closest I can find to anything that's documented is from perlmod,
"You can switch into a package in more than one place; it merely influences which symbol table is used by the compiler for the rest of that block."
Not entirely related, but if you read it obliquely, I think it suggests that there's no real benefit to using the module multiple times...unless (for some strange reason) you're modifying values in the module itself. Even then, I can't see how this would possibly make any difference. If you've used the module once, you've got to have a little bit of faith that it still exists within a few clock cycles.
Thoughts? Feedback?
--f
Update #2: Fixed a rather nasty typo that damian1301 caught. (Thanks.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: runtime "use" statements via string eval
by epoptai (Curate) on Apr 04, 2001 at 07:44 UTC | |
|
Re: Re: runtime "use" statements via string eval
by geektron (Curate) on Apr 04, 2001 at 05:08 UTC | |
by tilly (Archbishop) on Apr 04, 2001 at 17:34 UTC |