Looks great, but this doesn't work if the method expects parameters. For instance:
The reason is that can() returns only a reference to the method, but the object ($x) is lost on the way. A workaround would bepackage Obj; sub new { my $class=shift; my $self={ x => 'uh' }; bless $self, $class; } sub howl { my ($self,$arg)=@_; print($self->{x}," $arg\n"); } package main; sub mname { 'howl' } my $x=Obj->new(); $x->howl('oh'); $x->can(mname)->('ah');
but this is ugly, since it requires us to mention the object twice.$x->can(mname)->($x,'ah');
In reply to Re^2: Syntax question: Method call, where method name is calculated from an expression
by rovf
in thread Syntax question: Method call, where method name is calculated from an expression
by rovf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |