akagrawal3 has asked for the wisdom of the Perl Monks concerning the following question:

Does the following piece of code call multi-functions? Kindly also let me know if there is any alias to the following code. &{ $handler_for{ $action } }(%opts); Thanks in advance

Replies are listed 'Best First'.
Re: Function call
by tobyink (Canon) on Mar 02, 2012 at 08:36 UTC

    %handler_for is a hash, $action is a scalar.

    The value of $handler_for{$action} is either a coderef (a pointer to a sub) or if this is no-strict-refs code perhaps the name of a function as a string.

    &{ $handler_for{ $action } }(%opts) calls that function, passing it %opts as an argument. An alternative, perhaps clearer way of writing it might be:

    my $function = $handler_for{$action}; $function->(%opts);
Re: Function call
by moritz (Cardinal) on Mar 02, 2012 at 08:53 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>
        I actually meant that if it calls more than one function. I do not know the technical term for that.
      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?