in reply to eval inside an object
#code a my $function = $node->{'activationfunction'}; my $functionCall ="\$value = \$network->$function(\$value);"; eval($functionCall); #code b my $function = $node->{'activationfunction'}; $value = $network->$function($value);
Eval saved me once upon a time from having to learn that code b was possible. BUT, since I was calling this tens of thousands of times in normal program execution, and hence invoking the compiler every time, once I did learn that code b was possible, the program speeded up by several hundred fold!
The moral - eval is cool, but very very slow!
|
|---|