Greetings,
I'm looking for a clean way (ie, without using a shell call, grepping, etc) to obtain the list of package names in a module from a calling script.
For example, given the following module (Util/Stuff.pm):
package Util::Stuff;
use strict;
use warnings;
package Util::Stuff::aaa1;
sub flag { 1 }
...
package Util::Stuff::aaa2;
sub flag { 0 }
...
package Util::Stuff::aaa3;
sub flag { 1 }
...
...
1;
I now want to obtain the list programmatically:
Util::Stuff:aaa1
Util::Stuff:aaa2
Util::Stuff:aaa3
Once I have that info in a list, I want to get the flag values:
The manual/existing way:
use Util::Stuff;
my $temp1 = Util::Stuff::aaa1->flag;
my $temp2 = Util::Stuff::aaa2->flag;
my $temp3 = Util::Stuff::aaa3->flag;
The way I'd like:
use Util::Stuff;
my @names = **get_package_names(Util::Stuff)**
foreach my $name (@names) {
push @temp, $name->flag;'
}
Any pointers would be appreciated.
Regards
Henry
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.