in reply to Function refs, and trying to keep strict
If you don't want to use no strict 'refs'; you'll have to use hard references rather than symbolic references.
Something like:
and in your loop you'd make the call likemy @tests = \( &T::test0, &T::test1, . . . );
$test->($t); # Sending the $t object as the first arg...
An alternative might be to use eval()...
. . . unless eval "\$t->$test()";
If you go the hard reference route, you can use eval to create closures to wrap your method calls:
Then you populate another hash with your actual tests by using another map():sub create_closure { my $t = shift; my $m = shift; my $r = eval 'sub { $t->' . $m . '() }'; }
and then your loop changes to something likemy @execute{@tests} = map { create_closure( $t, $_ ) } @tests;
foreach my $test (@tests){ if($mask & $byte{$test}){ $mask = $mask ^ $byte{$test} unless &$execute{$test}; #if the test returned false we unset the bit } }
Which is best depends on what you are actually doing. Where does $t come from? If inheritance is an issue, avoid specifying the package as in my first example. If the tests do something complicated, you might prefer to avoid using eval... if $t is iterating over a list, you might want to avoid creating closures with eval. Etc. Etc.
P.S. None of this code has been tested.
-sauoq "My two cents aren't worth a dime.";
|
|---|