develooper Front page | perl.perl5.porters | Postings from January 2022

Re: Things you can't do in a signatured sub

Thread Previous | Thread Next
Paul "LeoNerd" Evans
January 21, 2022 17:11
Re: Things you can't do in a signatured sub
Message ID:
On Fri, 21 Jan 2022 16:49:22 +0000 (UTC)
Ovid <> wrote:

> I knew my 3VL discussion went over like a lead balloon, but I
> couldn't resist being cheeky ...
>     use Unknown::Values;
>     sub foo ($bar = unknown) {
>         say is_unknown $bar ? "unknown" : "known";
>     }
>     foo();
> That prints "unknown", so if someone passed in `undef`, it will print
> "known" because someone explicitly assigned to it.

Wellsure but now you've just moved the goalpost - how to distinguish


Ultimately, this comes down to the fact that since it is trivially easy
in perl to distinguish the values left in the @x array in:

  my @x = (undef);   # or (unknown);
  my @x = ();

The same easy distinction ought to be possible with subroutine
arguments. It always has been so far.

Paul "LeoNerd" Evans      |  |

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