develooper Front page | perl.perl5.porters | Postings from April 2000

Re: [ID 20000413.002] prototype for optional coderef parameter

Thread Previous
April 13, 2000 08:44
Re: [ID 20000413.002] prototype for optional coderef parameter
Message ID:
>>>>> On Thu, 13 Apr 2000 15:43:34 +0200, (ZRZ-Operator) said:

 > This is a bug report for perl from,
 > generated with the help of perlbug 1.28 running under perl v5.6.0.

 > -----------------------------------------------------------------
 > [Please enter your report here]

 > Please watch this:

 > perl -e 'sub foo (;&) {} foo {};'
 > Type of arg 1 to main::foo must be block (not single ref constructor) at -e line 1, near "};"

 > Calling foo with a bare block should be possible, at least perlsub doesn't
 > say otherwise.  The error goes away when you make the coderef parameter
 > required, changing "(;&)" to "(&)".

You are required to say

    perl -e 'sub foo (;&) {} foo sub {};'

 > The bug, if it is a bug, was present in Perl 5.5 as well, though the
 > message said "(not scalar ref constructor)" instead of "...single...".

I think the bug is currently a (unsufficiently?) documented
misfeature. Here the easy to miss sentence from man perlsub:

                                                An & requires an
       anonymous subroutine, which, if passed as the first
       argument, does not require the "sub" keyword or a
       subsequent comma.

That seems to need a rewording, maybe 

       .... if passed as the first mandatory argument ....


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