Is this possible using Perl:
my @array = ($class1,$class2,$class3);
foreach my $c (@array)
{
my $temp = $c->new();
$temp->run($var1,$var2);
}
The idea behind this is that the array will always contain different class names. I would then like to create an object of that class and run a method from it. Each class is somewhat similar but contains its own logic in the run method?
If this is not possible, is there a different way i could do this? Is this bad programming?
You need to make sure that the run-Method is always accessible:
my @array = ($class1,$class2,$class3);
foreach my $class (@array) {
my $temp = $class->new();
if ($temp->can('run') {
$temp->run($var1,$var2);
} else {
...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With