DJ_AM_Juicebox
asked on
Function pointer equivalent
Hi,
I'm trying to figure out this perl syntax for passing a function 'pointer'.
sub test (&@)
{
my ($function, @data) = @_;
}
so do the two egyptian hieroglyphs mean that the sub only takes a sub, then an array as parameters? How exactly do I pass a sub to a call of test(), like:
sub saysomething()
{
print("hello\n");
}
test(saysomething, @myarray);
If that's right, how can I then call $function once it's passed to test, and even pass a parameter to it?
Thanks
I'm trying to figure out this perl syntax for passing a function 'pointer'.
sub test (&@)
{
my ($function, @data) = @_;
}
so do the two egyptian hieroglyphs mean that the sub only takes a sub, then an array as parameters? How exactly do I pass a sub to a call of test(), like:
sub saysomething()
{
print("hello\n");
}
test(saysomething, @myarray);
If that's right, how can I then call $function once it's passed to test, and even pass a parameter to it?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The \& returns a reference to the subroutine. If you have the use strict and use warnings options turned on, it will not work without the \&.
ASKER
\&
before saysomething, I left it out and it still seems to work ok - what is the effect?
Thanks