in reply to Ref to Method?

can returns a code ref - but you have to emulate the class/object invocation ... does this help ?

Running this:

package foo; sub bar { warn "$self(@_)" } sub tell { $ref = \&bar; warn "$ref" } package main; $ref = foo->can('bar'); warn "$ref"; &$ref('foo'); foo->tell();
results in...
CODE(0x914dfb8) at tst.pl line 9. (foo) at tst.pl line 3. CODE(0x914dfb8) at tst.pl line 4.

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^2: Ref to Method?
by chromatic (Archbishop) on Mar 04, 2009 at 19:24 UTC

    That may be more obviously a method call as:

    my $ref = foo->can('bar'); warn "$ref"; foo->$ref(); foo->tell();