in reply to Call sub in variable module

Why? mydir::mymod123 smells awful. Tell us about the big picture because at the moment it looks like you have come up with a very common awful solution to some problem. We may be able to help you come up with a much better approach that will eliminate the need for numbered modules and other such weird games.

Premature optimization is the root of all job security

Replies are listed 'Best First'.
Re^2: Call sub in variable module
by tel2 (Pilgrim) on Nov 07, 2016 at 03:51 UTC
    My apologies for the apparent stench, GrandFather.

    mydir::mymod123 is just for demonstration.

    The $modno will probably not end up being a number at all, that was also for demonstration.

    Basically, some users will need different functionality from others, and I just want to "require" & call the appropriate bits.

      You still haven't given us a big picture. I can imagine various scenarios where you are providing an engine (web site, build system, data server, ...) where you want to provide a plug in system for users. There are well established techniques for doing those jobs and none of them require the engine to know implementation details of the plug ins.

      Maybe you have a task that is quite different, but it's a pretty good bet that the techniques used for plug in architectures can be applied here.

      Something to think about is either requiring your users to use a common interface or even to derive their code from a common base class you provide. On the face of it your problem would be solved if your users bend a little, or even if you write shims around their code, so that your engine doesn't become a maintenance nightmare.

      Premature optimization is the root of all job security
      some users will need different functionality from others, and I just want to "require" & call the appropriate bits.

      Perhaps a better, easier to maintain, approach would be to put the common parts in to a module. Then write function specific programs that use (or require) the common module.

      If function modules already exist, then each function-specific program would just use (or require) whichever function module (or modules) is (are) needed, as well as the common module.