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

//= and ||= in subroutine signatures

Thread Next
Ivan Vorontsov
September 3, 2023 08:48
//= and ||= in subroutine signatures
Message ID:
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 <>

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About