With a normal sub I can do this:
$ref = \&MyFunc;
..which will make $ref a reference to the sub MyFunc. But
how do I do it if MyFunc is a method in the $self object?
I want to make a reference to
$self->MyFunc so $self is
passed when I call it, but neither
$ref = \&$self->MyFunc;
nor
$ref = \$self->MyFunc;
seems to work. Perl says "Undefined subroutine" for the
first, and "not a CODE reference" for the second. So,
question is, how do I reference a method so the object is
sent when I call the reference, or is there a workaround for
the problem?
Originally posted as a Categorized Question.
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.