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

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

Thread Previous | Thread Next
Ovid via perl5-porters
January 21, 2022 16:49
Re: Things you can't do in a signatured sub
Message ID:
On Wednesday, 19 January 2022, 19:00:12 CET, Paul "LeoNerd" Evans <> wrote:

>      sub signatured($x = undef) {
>        # impossible to distinguish signatured() from signatured(undef)
>      }

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";


That prints "unknown", so if someone passed in `undef`, it will print "known" because someone explicitly assigned to it.

IT consulting, training, specializing in Perl, databases, and agile development 

Buy my book! -

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