develooper Front page | perl.perl5.porters | Postings from October 1999

Re: mjd reminded me... (;$) prototype...

From:
M.J.T. Guy
Date:
October 26, 1999 17:12
Subject:
Re: mjd reminded me... (;$) prototype...
Message ID:
E11gGhB-0002UL-00@taurus.cus.cam.ac.uk
Ronald J Kimball <rjk@linguist.dartmouth.edu> wrote
> At 12:14 26/10/99 -0400, Jeff Pinyan wrote:
> >Why does
> >
> >  sub foo (;$);
> >  print foo $a, $b;
> >
> >whine that foo has too many arguments?
>
> I might expect that to be parsed as:
>
> print foo($a), $b;

Me too!          :-)

And I thought "Hey  -  that's all documented in perlsub" and went to look
it up.    I expected to find an example like

         sub mylength(;$)         mylength $a

but it wasn't there.    Instead there was

         sub myrand ($)           myrand 42

But I can write

      print rand,rand;

and it Does The Right Thing.   Whereas if I write

      sub myrand($) { rand() };
      print myrand,myrand;

I get

      syntax error at - line 2, near "myrand,"

So there seems to be a serious confusion between the prototypes (;$)
and ($).    The builtins such as length() and rand() behave as if they
had prototype (;$), but are documented as having ($).    And a user
defined subroutine can't imitate them with either prototype.


Mike Guy



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