in reply to Is dynamic loading of pm's a bad thing?

According to the documentation, the difference between require $parser and, something like require Module::Parser is that in the latter case, it replaces '::' with '/' and tacks a '.pm' on the end. Seems like you could do that yourself, and avoid the eval:
$parser =~ s#::#/#g; $parser .= '.pm' unless $parser =~ /\.pm$/; require $parser;
This answer is too easy to be right. But I'd appreciate it if someone would explain why it's wrong.

We're not really tightening our belts, it just feels that way because we're getting fatter.

Replies are listed 'Best First'.
Re^2: Is dynamic loading of pm's a bad thing?
by eserte (Deacon) on Jun 25, 2004 at 08:36 UTC
    A more portable solution would be $parser = File::Spec->catfile(split /::/, $parser) . ".pm";
Re^2: Is dynamic loading of pm's a bad thing?
by bunnyman (Hermit) on Jun 25, 2004 at 15:41 UTC

    Why bother doing this at all? All you've actually done is written more lines of code and made it less portable than it was before.

      All you've actually done is written more lines of code and made it less portable than it was before.
      What was it before? How is it less portable now?

      Consider the problem: dynamically loading pm's. That means that the module to be loaded might just be input by a user. You can't just use a hardwired name. The only other solution offered was eval, which comes with security issues.


      We're not really tightening our belts, it just feels that way because we're getting fatter.