[EMAIL PROTECTED] wrote: > Hi all, > > I have a module which does nothing but include a bunch of use statements > (Shawn > Corey, I think you taught me how to do that).It looks like this: > > ---------------------------------------------------------------------------------- > #PerlMQ.pm > > use strict; > use warnings; > > use statement1; > use statement2; > use statement3; > > #and so on... > > 1; > > _END_ > > -------------------------------------------------------------------------------- > > In my script, I load the module by saying "use PerlMQ;". However, now I want > to > load only certain use statements from the module depending on the parameter I > give it. For example, in my script, I want to say "use PerlMQ > qw(some_parameter)" in order to load the use statements specified by > some_parameter in the module. Is it possible to do that? >
Because 'use' happens at compile time rather than at runtime this is more difficult to accomplish then just wrapping them in an if statement for instance. One way to load modules based on conditions is to wrap the loading of the module in an C<eval EXPR> statement. It would look something like, if (condition) { eval "use <module name>"; if ($@) { die "Failed to load <module name> module at runtime: $@"; } } You can then use the module as usual, however you must be certain that all calls to the module's subs are wrapped in a check to make sure they are available, or you need to make sure a replacement module did get loaded that handles the same calls. Basically don't call something that hasn't been loaded, which is the tricky part of loading or not loading a module. perldoc -f eval > Most of the examples on the web seem to use the EXPORT package while providing > the qw(some_parameter) functionality in the script. How do I do it in my > module > which seems pretty unconventional? > That is for loading items into the symbol table (usually) from the particular module and can't really help you with runtime loading of modules. http://danconia.org > Thanks > > Vishal > > ---------------------------------------- > This mail sent through www.mywaterloo.ca > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>