On 18 May 2004, at 19:58, Joseph Alotta wrote:

Greetings,

I am writing a solving function. You pass it the name of a function and it
calls the functions many times until it finds the value that returns zero. How would
this be set up?

If you really want to pass the name of the function, then use something like the following:


        #!/usr/local/bin/perl -w
        use strict;
        no strict 'refs';

        my $function = 'hello';
        &$function();

        sub hello
        {
            print "Hello, World!\n";
        }

Assuming you always use strict, you need the no strict 'refs' line,
else perl will complain.

Instead of passing the name of the solver, you could pass a reference:

        #!/usr/local/bin/perl -w
        use strict;

        my $function = \&hello;
        &$function();

        sub hello
        {
            print "Hello, World!\n";
        }

Notice you don't need the no strict line. If you were passing the name because
it's user input, you could have a hash with the user input as keys, and function
refs as values.


Neil



Reply via email to