L
lapenta[
Hello,
I am trying to map out a simple PERL program to optimize coefficents for
a dynamic list of equations based on a set of rules. I'm having trouble
figuring out how to efficiently and dynamically load different
equations. Idealy separate files would each define the equation and
rules, while the main tool would load 1...n equations at a time and run
the optimization algorithm. As the equation will be executed many times
during the optimization, execution speed is a factor. I was thinking
dynamic modules would work nicely, but I can not figure out how to get
them to work. I would like to avoid doing something like 'exec "perl
$eqn"' as I imagine that would be much too slow for many equations.
for example...
file1.pl
----------------------------------------------
#!/usr/bin/perl -w
BEGIN{
$g_module = $ARGV[0];
}
print "optimizing for $g_module\n";
require "$g_module.pm";
$g_module::eqn( 5, 6 );
----------------------------------------------
simple_eqn.pm
----------------------------------------------
package simple_eqn;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(eqn $g_vars);
$g_vars = 2;
sub eqn {
my $a = shift;
my $b = shift;
return ($a / $b)**($a);
}
----------------------------------------------
$ perl file1.pl simple_eqn
syntax error at file1.pl line 14, near "$g_module::eqn( "
Execution of file1.pl aborted due to compilation errors.
Thanks in advance,
Jason
I am trying to map out a simple PERL program to optimize coefficents for
a dynamic list of equations based on a set of rules. I'm having trouble
figuring out how to efficiently and dynamically load different
equations. Idealy separate files would each define the equation and
rules, while the main tool would load 1...n equations at a time and run
the optimization algorithm. As the equation will be executed many times
during the optimization, execution speed is a factor. I was thinking
dynamic modules would work nicely, but I can not figure out how to get
them to work. I would like to avoid doing something like 'exec "perl
$eqn"' as I imagine that would be much too slow for many equations.
for example...
file1.pl
----------------------------------------------
#!/usr/bin/perl -w
BEGIN{
$g_module = $ARGV[0];
}
print "optimizing for $g_module\n";
require "$g_module.pm";
$g_module::eqn( 5, 6 );
----------------------------------------------
simple_eqn.pm
----------------------------------------------
package simple_eqn;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(eqn $g_vars);
$g_vars = 2;
sub eqn {
my $a = shift;
my $b = shift;
return ($a / $b)**($a);
}
----------------------------------------------
$ perl file1.pl simple_eqn
syntax error at file1.pl line 14, near "$g_module::eqn( "
Execution of file1.pl aborted due to compilation errors.
Thanks in advance,
Jason