If EXPR is a bareword, the require assumes a ".pm" extension and replaces "::" with "/" in the filename for you, to make it easy to load standard modules. This form of loading of modules does not risk altering your namespace.Having been bitten by this in some code that needs to require the module based on a run time value (solved the problem with an eval), I wonder what the underlying reasons are for not applying the same rules for a scalar string as for a bareword.In other words, if you try this:
The require function will actually look for the "Foo/Bar.pm" file in the directories specified in the @INC array.require Foo::Bar; # a splendid barewordBut if you try this:
The require function will look for the "Foo::Bar" file in the @INC array and will complain about not finding "Foo::Bar" there. In this case you can do:$class = 'Foo::Bar'; require $class; # $class is not a bareword #or require "Foo::Bar"; # not a bareword because of the ""...eval "require $class";
Is it
How much code would break if this were made consistent? (not much as far as I can think of)
I also notice that use similarly insists on a bareword.
--
I'm Not Just Another Perl Hacker
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing a run time string to require
by Corion (Patriarch) on Oct 22, 2004 at 17:10 UTC | |
by rinceWind (Monsignor) on Oct 22, 2004 at 23:29 UTC | |
by BUU (Prior) on Oct 23, 2004 at 03:46 UTC | |
by rinceWind (Monsignor) on Oct 23, 2004 at 08:32 UTC | |
by BUU (Prior) on Oct 23, 2004 at 09:07 UTC | |
|
Re: Passing a run time string to require
by Anonymous Monk on Oct 22, 2004 at 15:39 UTC |