Exposing my ignorance, wanting help with use!

Uri Guttman uri at stemsystems.com
Wed Feb 14 16:35:56 GMT 2007


>>>>> "LR" == Luke Ross <luke at lukeross.name> writes:

  >>> From the man pages:

  LR> If EXPR is a bareword, the require assumes a ".pm" extension
  LR> and replaces "::" with "/" in the filename for you, to  make it
  LR> easy to load standard modules.  This form of loading of modules
  LR>                does not risk altering your namespace.

  LR> Unfortunately your require does not use a bareword. You could say 
  LR> something like

  LR> $var = "$module.pm"; eval { require $var; }

that will still fail. the :: are not converted to / in a filename, only
with a bareword class name.

  LR> or perhaps easier to follow, but less efficient

  LR> eval "require $module;"

that is the standard idiom for doing a runtime require with a
classname. or if the OP wants to convert the :: to / and append a .pm
then you can do require $module_file. i used to do that but the eval
"require $module" is much cleaner. one of the few cases where i
recommend eval string as a simpler and better way.

uri

-- 
Uri Guttman  ------  uri at stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


More information about the london.pm mailing list