Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Answer: How do I reference methods?

( #62739=categorized answer: print w/ replies, xml ) Need Help??

Q&A > object-oriented programming > How do I reference methods? contributed by davorg

All very kludgy, but you could do something like the following. Remember that the first parameter to an object method must be a reference to an object of the right type.

#!/usr/bin/perl -w use strict; package Thing; sub new { bless {}, shift; } sub say { print "@_[1 .. $#_]\n"; } package main; my $thing = Thing->new; $thing->say('Hello', 'World'); my $say = \&Thing::say; $say->($thing, 'Goodbye', 'All');

Comment on Answer: How do I reference methods?
Download Code
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2015-11-28 14:46 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (742 votes), past polls