In the context of OO code you could:
use strict; use warnings; my $self = bless {tests => [qw(something else another bogus)]}; for my $testName (@{$self->{tests}}) { my $test = $self->can ("test_$testName"); if (! $test) { warn "Test $testName not available\n"; next; } print "Running test $testName:\n"; $test->($self); } print "Testing complete\n"; sub test_something { print "something\n"; } sub test_else { print "something else\n"; } sub test_another { print "another unimaginative statement\n"; }
Prints:
Running test something: Test bogus not available something Running test else: something else Running test another: another unimaginative statement Testing complete
which allows derived classes to add tests that are managed by the parent class.
In reply to Re: How to call sub defined in a variable?
by GrandFather
in thread How to call sub defined in a variable?
by jh-
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |