develooper Front page | perl.perl5.porters | Postings from December 2021

Re: "no snails"; or having signatured subs complain about @_

Thread Previous | Thread Next
Juerd Waalboer
December 3, 2021 19:59
Re: "no snails"; or having signatured subs complain about @_
Message ID:
Paul "LeoNerd" Evans skribis 2021-11-29 16:08 (+0000):
>The final part of the "signatures" feature still to be implemented, is
>getting rid of the @_ setup

If I understand correctly, accessing @_ is currently commonly used to determine whether an optional argument was passed:

     sub bar($self, $new = "blah") {
         $self->{bar} = $new if @_ == 2;


     $x->bar(undef);  # set bar to undef

Or maybe I'm missing something.

Now, one could hack around that with a constant that is near impossible to accidentally pass as the argument...

     use constant NONE => \do { my $x };
     sub bar($self, $new = NONE) {
         $self->{bar} = $new unless ref($new) and refaddr($new) == refaddr(NONE);

That would be ugly, but if that's what it takes to finally get signatures out of experimental status after 8 years, I'd take it. However, it seems to me that there should be a better, and officially supported, way to do this.
Met vriendelijke groet, // Kind regards, // Korajn salutojn,

Juerd Waalboer  <>

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