reference to object method

U

Uri Guttman

JB> Ah, is it time for the "Your mother ..." jokes?

yes, yapc::na is approaching fast!

uri
 
H

Hobo Salesman

Uri said:
yeah, the OP's original issue is long lost in my skull. and i bet he
isn't reading this thread anymore!

Actually I am, but lurking. I don't think my skills are the level of a
lot of people here and I'm still getting familiar with the group so I'm
doing more reading than posting.
 
S

Sherm Pendley

Hobo Salesman said:
Actually I am, but lurking. ... I'm still getting familiar with the group
so I'm doing more reading than posting.

An *excellent* attitude that's far too rare. Congratulations - you're one of
handful of Google Groups users who have managed to climb out of my killfile.

sherm--
 
H

Hobo Salesman

Sherm said:
An *excellent* attitude that's far too rare. Congratulations - you're one of
handful of Google Groups users who have managed to climb out of my killfile.

Don't write off google groups users too soon, some (like me) know how
usenet works but have trouble finding a usenet provider that allows
posting. I also like being able to use my google groups account from
any machine. The downside is the extremely lousy interface, I can't
even figure out how to show the thread structure, it's all in a big
linear list.
 
C

Charles DeRykus

Hobo said:
Can I store a reference to an object method in a scalar and use that to
call the method? Something like (and I'm sure this is wrong):

$methodRef = \$object->method();

No, that invokes the method and gives you a reference to the return
value (or last return value if the method returns a list)*.

* See Recipe 11.8 "Creating References to Methods" in the `Perl
Cookbook`. The recipe explains why UNIVERSAL's `can` method falls
short as well.

And, as mentioned though, the working solutions don't preserve inheritance.
 
B

Ben Morrow

Quoth Charles DeRykus said:
No, that invokes the method and gives you a reference to the return
value (or last return value if the method returns a list)*.

The method doesn't return a list. ${} provides scalar context.

(Yes, I know I've argued against the 'there are no lists in scalar
context' model in the past. I accepted that it mekes it easier for most
people to understand what's going on :) )

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top