develooper Front page | perl.perl5.porters | Postings from September 2023

Re: //= and ||= in subroutine signatures

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
September 4, 2023 15:44
Subject:
Re: //= and ||= in subroutine signatures
Message ID:
ZPX7TXcsLNod5+bc@iabyn.com
On Mon, Sep 04, 2023 at 06:25:57PM +0300, Ivan Vorontsov wrote:
> >     f($x, $y //= 1,  $z = 2)    # $y is optional parameter
> 
> This is an intermediate case. To a caller $y is optional, but $y
> must have undef value either explicitly or implicitly to trigger the
> assignment, $z must not accept argument at all to get assigned. I would
> call $y semi-optional :)

I don't understand what you are trying to say there. The difference
between a mandatory and optional argument is that perl will croak() 
if not enough  mandatory arguments are passed to the function.

Given

    f($x, $y //= 1,  $z = 2)    # $y is optional parameter

what do you expect the result to be for each of these (i.e. croak, or $y
assigned the value 2, or whatever)?

    f(1);
    f(1,2);
    f(1, undef);
    f(1, 2, undef);


-- 
Monto Blanco... scorchio!

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About