in reply to requiring perl modules

According to require, if the argument to require is not a bareword (if it's a variable as you have or an expression returning a name), Perl doesn't automatically add the .pm extension. I suspect you could get by with something like this:

use File::Spec; my $dir = 'modules'; my $mod = 'test'; my $module = File::Spec->catfile( $dir, $mod . '.pm' ); require $module;

The documentation also suggests this, which I don't like, though it is shorter:

eval "require $mod";

Replies are listed 'Best First'.
Re: Re: requiring perl modules
by ysth (Canon) on Dec 03, 2003 at 19:28 UTC
    It was my recollection that require expected (or at least allows) a posix-style pathname, e.g. require "$dir/$mod.pm". Could someone on VMS or a Mac try with catfile, with '/', and via eval "require $mod" and report which work (as well as what they put in %INC)? I would find it very helpful to know for sure.