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

//= and ||= in subroutine signatures

Thread Next
From:
Ivan Vorontsov
Date:
September 3, 2023 08:48
Subject:
//= and ||= in subroutine signatures
Message ID:
20230903114814.87e1cc1f6d0e8471dc71fe17@yandex.ru
With perl v5.38.0 I wrote a code similar to:
    perl -E 'sub foo ($x, $y //= 42, $z) {} foo(1, undef, 3)'
and got the error:
    Mandatory parameter follows optional parameter at -e line 1, near "$z) "

So //= and ||= mark a parameter as optional, but optional parameters must follow mandatory ones. Outside of signatures these operators check a value of a variable. A mandatory parameter can have undef or false value. If it is feasible, maybe these operators could be applied to mandatory parameters as well.

-- 
Ivan Vorontsov <ivrntsv@yandex.ru>

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