in reply to Function call

Perl 5 does not support multi functions. What your piece of code does is calling an anonymous subroutine. See Higher Order Perl for more information.

Another way to write this is $handler_for{ $action }->(%opts). See perlreftut and perlref for more information.

Replies are listed 'Best First'.
Re^2: Function call
by rovf (Priest) on Mar 02, 2012 at 09:01 UTC
    Perl 5 does not support multi functions.
    Just being curious: What exactly is a multi function? I googled only this reference, where it says that multifunction is just another name for a multi-valued function. Since Perl can return lists (or sets), this would at least make it possible to model a multi-valued function easily. Is there maybe another meaning for the word "multifunction"?

    -- 
    Ronald Fischer <ynnor@mm.st>

        That's correct. But in Perl 6 it's not restricted to methods, it also works on subroutines.

        Basically it means that you have several routines (called "candidates" in p6 speak) with the same name but different signatures, and the closest match between the run-time argument list and the signatures determines the candidate to call

        $ perl6 -e 'multi f(0) { 1 }; multi f(Int $x) {$x * f($x - 1) }; say f + 5' 120

        The lack of subroutine signatures and user-exposed core types make it hard to introduce multis in Perl 5; but some of the current improvements and plans for Perl 5 make me hopeful that some day we'll have enough infrastructure to support them.

        S06 has many more details on the Perl 6 multis.

        Even with multiple dispatch, just one method is called. Multiple dispatch allows you to have several methods with the same name, but because the signature is different (that is, each of them accepts a different set of parameter types), the compiler can figure out which one should be called.

        It's a little bit like Perls ability to have a scalar, array, hash, subroutine and filehandle, all by the same name, and still knowing which is which. Or values having both string and numeric values, without Perl getting confused.

      I actually meant that if it calls more than one function. I do not know the technical term for that.

        It just calls one functionsub. Although which sub that is can be different every time.

        It just calls one functionsub. Although which sub that is can be different every time.

Re^2: Function call
by akagrawal3 (Beadle) on Mar 02, 2012 at 09:11 UTC
    Does that mean that if %opts has keys whose value is a subroutine name then in that case will it call all the subroutine(values of keys) of every key?
        Thank you :)