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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How do I reference methods?⭐
by Joost (Canon) on May 24, 2002 at 16:39 UTC | |
Re: How do I reference methods?
by RocketInABog (Initiate) on Dec 23, 2008 at 12:45 UTC | |
Re: How do I reference methods?
by LanX (Saint) on Dec 23, 2008 at 12:54 UTC | |
Re: How do I reference methods?
by mirod (Canon) on Mar 07, 2001 at 18:09 UTC | |
Re: How do I reference methods?
by davorg (Chancellor) on Mar 07, 2001 at 17:07 UTC | |
Re: How do I reference methods?
by ariels (Curate) on Aug 20, 2001 at 17:34 UTC | |
Re: How do I reference methods?
by Anonymous Monk on May 24, 2002 at 11:31 UTC |
Back to
Seekers of Perl Wisdom