Chris Devers <mailto:[EMAIL PROTECTED]> wrote:
: : Ahem. It is most useful when I want to determine the module to load : : dynamically, or when I want to load a module only if necessary to : : save the time spent compiling it in the cases when it is not needed. : : :-) : : I think that counts as an esoteric-enough requirement that beginners : can safely ignore the need for it unless & until they hit that wall. : : I'm assuming that most beginners won't be writing much or any code : that needs to optimize loading a module multiple times... Dynamic loading does not apply just to multiple loading of a single module. It could also be used to check the existence of a module before loading it. An answer to the original question is incomplete without at least a mention of the usefulness of 'require' under some intermediate to advanced perl programming. my $mail_module = load_mail_module(); warn q(No mail module) unless $mail_module; sub load_mail_module { eval { require mail_foo }; unless ( $@ ) { mail_foo::import(); return 'mail_foo'; } eval { require mail_bar }; unless ( $@ ) { mail_bar::import(); return 'mail_bar'; } eval { require mail_baz }; unless ( $@ ) { mail_baz::import(); return 'mail_baz'; } return; } ... or to load modules only as needed. print redirect( '/' ); sub user_data_form { require Data::FormValidator; Data::FormValidator::import(); # ... } sub redirect { my $page = shift; require CGI; return CGI::redirect( $page ); } __END__ HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>