in reply to Re: filename dynamic
in thread filename dynamic

The code that you suggested did work perfectly but i did not understand the concept behind it. It would be good if you can tell me what exactly is happening there. Also why did the following did not work

require pckg1::pckg2::$filename; $result= pckg1::pckg2::$filename::functionname(argument list)

the above one is giving the error of BAD code after ::

Replies are listed 'Best First'.
Re^3: filename dynamic
by choroba (Cardinal) on May 13, 2014 at 11:46 UTC
    See the documentation of require. It expects a version or expression as an argument. pckg1::pckg2::$filename is neither one. Namespace can't be built dynamically, you have to access the symbol table to do that. In my code, I use the form of require that isn't a bareword, so it's understood as a filename (that's why I add ".pm" to it). To be able to access the symbol table, you have to turn strict refs off. Then, you can reference the symbol table of a namespace as a hash of the same name plus ::. See Of Symbol Tables and Globs to learn more about symbol tables.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ