I have a directory structure that looks like:
Foo::Bar::Baz::1
Foo::Bar::Baz::2 etc
Can I list the packages from something like:
use Foo::Bar::Baz;
Thanks!
Edit: Made it more clear what the modules are.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just to be clear, are you looking at random packages in random Perl code?
Or for Perl modules, e.g. “a/b/c/d1.pm” with module “a::b::c::d1”?
In either case, you can not use a single “use” statement to load them all.
What you need to do is to find all the appropriate files, using either
globorFile::Find.In the first case (modules), you can then load them either by
require-ing each file, OR by converting filename into module name (s#/#::#g; s#\.pm$##;) and callinguseon each module individually.As far as actual packages nested in random Perl files, those packages can be:
Listed by grepping each file (again, found via
globorFile::Find) for/^package (.*);/Actually loaded by executing
require $filefor each file.In this case, please note that the package name for each of those packages in
a/b/c/1.plwill NOT need to be related to “a::b::c” – e.g. they CAN be named by the file author “p1”, “a::p1” or “a::b::c::p1_something”.