Assuming I have an obj reference $obj, that has a method foo such that $obj->foo returns something, what's the easiest way to get the return value of $obj->foo if the method name is stored in a scalar $method?
You can do:
# want the result of $obj->foo stored in $return_value my $method = 'foo'; my $return_value; eval '$return_value = $obj->'.$method; # now $return_value has what you need
But this seems clumsy and I doubt it's the best way. What's the right way to do this?
In reply to How to access an object method when method name is stored in scalar variable by tj_thompson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |