Monk-o-ramas,
I've had great experience (2 for 2) finding answers to my questions
here, so I thought I'd say thanks first of all for helping me out before.
Now, the present question. I'm trying to write a method that will
go through the current object (hash) and execute all methods that begin
with the '_' character. This is what I have:
sub runTests {
my ($self) = @_;
foreach $symname (sort keys %{$self}::) {
local *sym = ${$self}::{$symname};
&$symname if ((definined &sym) && ($symname =~ /_\.*/));
}
} # sub runTests
I saw this example in the camel book, but Larry (or Tom
or that other guy), had access to the name of the hash,
where I don't (well, I'm sure I do, but I don't know how
to get it) since I'm inside of an object that hasn't
been created yet. I'm getting an error that says:
Bad name after :: at Criteria.pm line 68 (line 68
has the foreach in it) when I run 'perl -c Criteria.pm.'
]
Thanks in advance!
Mark
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.