in reply to How do I dynamically declare a package name for

I'd use require:
require $module; import $module;

Replies are listed 'Best First'.
Re: Re: How do I dynamically declare a package name for
by hdp (Beadle) on Apr 27, 2001 at 16:22 UTC
    The caveat here is that since you're not giving require a bareword, you don't get the benefit of the filename niceties it would give you; in other words, you can't use $module = "Foo::Bar" and have require do the right thing (unless the right thing is to load a file called, literally, 'Foo::Bar').

    It's been my experience that people don't really expect that, and sometimes miss the fact that the error message says "Can't find Foo::Bar in @INC..." instead of "Can't find Foo/Bar.pm in @INC..."

    hdp.