Faidros has asked for the wisdom of the Perl Monks concerning the following question: ⭐ (object-oriented programming)
With a normal sub I can do this:
..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 = \&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?$ref = \$self->MyFunc;
Originally posted as a Categorized Question.
Back to
Seekers of Perl Wisdom