I want to use a method of an object. Like $myObject->helloWorld().
$myObject->helloWorld()
However there are a couple of methods so I loop through an array of method names and call the method like this:
my $methodName ="helloWorld"; $myObject->$methodNames;
This works quite nice but some objects don't have all methods.
How can I tell whether $myObject has a method called helloWorld or not?
$myObject
helloWorld
You can use the UNIVERSAL::can method of all objects to determine what methods it supports:
UNIVERSAL::can
if ($myObject->can($methodName)) { $myObject->$methodName; }
1.4m articles
1.4m replys
5 comments
57.0k users