On Sun, Sep 3, 2023 at 11:32â¯AM Dave Mitchell <davem@iabyn.com> wrote: > On Sun, Sep 03, 2023 at 11:48:14AM +0300, Ivan Vorontsov wrote: > > 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. > > I don't see how that could work. It makes for an ambiguity. I generally find that if I need more than two parameters and some are optional, switching to named parameters fixes the issue. It also makes it easier to distinguish between the cases of "not passed" and "undef passed." Best, Ovid -- Curtis "Ovid" Poe -- CTO, All Around the World World-class software development and consulting https://allaroundtheworld.fr/Thread Previous