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

Re: [ID 20000413.002] prototype for optional coderef parameter

Thread Previous
From:
andreas.koenig
Date:
April 13, 2000 08:44
Subject:
Re: [ID 20000413.002] prototype for optional coderef parameter
Message ID:
m3u2h6roof.fsf@ak-71.mind.de
>>>>> On Thu, 13 Apr 2000 15:43:34 +0200, operator@periszrz.zrz.tu-berlin.de (ZRZ-Operator) said:

 > This is a bug report for perl from siegel@zrz.tu-berlin.de,
 > 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 ....

Cheers,
-- 
andreas

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About