in reply to Re: runtime "use" statements via string eval
in thread runtime "use" statements via string eval

there's one major difference, and i guess it wasn't quite clear from the first post.

you're still useing the modules at the beginning, even though they're wrapped in an eval. and they're wrapped in an eval for a reason -- you're handing the scripts off to folks who may or may not have that resource.

the issue, with more context:

sub do_stuff { ### some stuff eval "use Foo::Bar::Baz;"; die if $@; ## do stuff with the imported functions }
in some cases, the same  eval "use Foo::Bar::Baz;"; will end up in a different sub, same module. . .

there's no 'hand off to client' - these are all internally-developed modules. . .

i know that it's perfectly legal perl syntax . . . . it just doesn't sit quite right with me . .

UPDATE: the thing is, and i haven't made it clear, is that the module being used in the eval string is NOT being used on 'initialization' ( for lack of a better word ). there's no 'use Foo:Bar::Baz;' at the beginning for the module. . .

and i've been looking to see if there were any other issues than 'bad style'.

Replies are listed 'Best First'.
Re (tilly) 3: runtime "use" statements via string eval
by tilly (Archbishop) on Apr 04, 2001 at 17:34 UTC
    First of all I think that external dependencies like that should be up front and obvious.

    Secondly each string eval ties up memory. If this is called in a tight loop, you will have a serious memory leak.

    A better way to do it is:

    require Foo::Bar::Baz; Foo::Bar::Baz->import();
    and leave out the second line if it is not necessary.