Hi Todd,

This is more of a general Perl question, perhaps for the macperl-anyperl
list.

Briefly, though, it looks like you'd benefit from using code references
(assuming I understand your question correctly):

 sub hello {
   my $name = shift;
   return "Hello, $name!\n";
 }

 sub foo {
   my($f, @args) = @_;
   return &$f(@args);
 }

 print foo(\&hello, "world");

Creating a reference to a function is done by preceding the function call
with a backslash, e.g.,

 my $hello_ref = \&hello;

Calling the function referred to by a code reference is then done by
prepending the & sigil to the code reference and adding any arguments inside
parens:

 &$hello_ref;          # no args
 &$hello_ref("world"); # with args

In your example,

> F(f(),\@a,$n);

the first argument to F() is actually the *return value* of f(), which is
probably not what you want.

Hope that helps. If not, you may want to clarify your question in a post to
the macperl-anyperl list.

Best regards,
David Iberri

At 11/11/2002 7:40 PM, todd shifflett wrote:

> This may be a bit of a beginner question but...
> 
> 
> I have function f(@a).
> 
> I would like to create another function, F(f(),\@a,$n), which can take
> f() as the parameter with its operands seperately.
> 
> i.e.
> F(f(),\@a,$n);
> 
> ##---- Simplified sample  vv
> sub f {
> my $array = shift;
> 
> print "$array[0]\n";
> 
> }
> 
> sub F {
> my $func = shift;
> my $array = shift;
> my $value = shift;
> 
> my @tmp = splice(@{$list},$window);
> 
> ##-- Here $func should be f(@tmp).  How do I do this?
> return eval($func(@tmp));
> 
> }
> ##---- ^^
> 

Reply via email to