From 507dc3692d6ee9cd449efce2f72080c4666065b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20J=C3=B6rg?= Date: Sun, 2 Nov 2025 18:32:27 +0100 Subject: [PATCH] [PATCH] Docu suggestion for named parameters in signatures Add a paragraph that callers need to specify all positional parameters before named ones, even if the positional parameters have defaults. Delete a sentence stating that there is no way for the caller to provide a value for a named parameter after an optional positional parameter. There _is_ a way, you just need to provide values for positional parameters. --- pod/perlsub.pod | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pod/perlsub.pod b/pod/perlsub.pod index ba6bf5d01683..b2b24e8f5450 100644 --- a/pod/perlsub.pod +++ b/pod/perlsub.pod @@ -476,6 +476,11 @@ is not important; both of the following lines will cause the same behaviour: foo(alpha => "A", beta => "B"); foo(beta => "B", alpha => "A"); +If a function declares both positional and named parameters, then +callers must provide values for all positional parameters before +providing values for named parameters, even if the positional +parameters have default values. + It is not important where these parameter names come from in the caller. In simple cases they could be literal strings such as the previous example, or they could themselves come from other variables. Expanding a hash variable @@ -507,12 +512,10 @@ left to right, as required. As with positional parameters, each expression can see and make use of the values assigned to any previous parameter. If the subroutine already declares any optional positional parameters, then -all named parameters must also be optional. It would not make sense to -require a mandatory named parameter after any optional positional ones, as -there would be no way for the caller to provide a value for it. However, if -the subroutine does not declare any optional positional parameters, then any -named ones may be freely mixed between mandatory and optional, since they are -processed by name and not position. +all named parameters must also be optional. However, if the subroutine does +not declare any optional positional parameters, then any named ones may be +freely mixed between mandatory and optional, since they are processed by +name and not position. After positional or named parameters, additional arguments may be captured in a slurpy parameter. The simplest form of this is just an array variable: @@ -1644,7 +1647,7 @@ example, satisfies C<\%>: my %hash $hashref->%* %{ expr } - (expr)->*% + (expr)->%* The value passed as part of C<@_> will be a reference to the actual argument given in the subroutine call,