If you wanted to make sure the method exists you could trap errors with the other form of eval (called "try" in other languages):
my $rv; if (!eval { $rv = $doomsday_weapon->$method(@args); 1 }) { die("Doomsday weapon failed: $@\n"); }
Or you could use can:
my $method_ref = $doomsday_weapon->can($method) or die("Method $method not supported by this doomsday weapon\n"); $method(@args); 1 }) { die("Doomsday weapon failed: $@\n"); } my $rv = $doomsday_weapon->$method_ref(@args);
In reply to Re: Calling a method by name without eval()
by ikegami
in thread Calling a method by name without eval()
by atemerev
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |