On Wed, 2002-04-17 at 20:25, drieux wrote:
>
> I just found this in the perldoc
>
> " Currently Perl subroutines have fairly limited
> support for formal parameter lists. You can specify the
> number of parameters and their type, but you still have to
> manually take them out of the `@_' array yourself. Write a
> source filter that allows you to have a named parameter
> list. Such a filter would turn this:
>
> sub MySub ($first, $second, @rest) { ... }
>
> into this:
>
> sub MySub($$@) {
> my ($first) = shift ;
> my ($second) = shift ;
> my (@rest) = @_ ;
> ...
> }
> "
>
> does this still make sense?
>
> does it improve the compiled object any?
>
> and why not
>
> sub MySub($$@) {
> my( $first, $second, @rest ) = @_;
> ...
> }
>
> ????
>
>
> ciao
> drieux
The use of shift instead of () = @_ is mainly a style issue; however,
there is one important difference: when you call a subroutine like this
&subname -- note the lack of parenthesis -- the @_ variable gets passed
into it. Shift removes elements from @_ so they don't trickle down.
As for formal parameters in Perl 5.x, they come with massive caveats:
only take effect if the sub is declared before it is seen in code, if
you say &subname() then the parameter definitions are ignored, the
parameter check is only done at compile time so it is useless for OO
code, and a pack of other warnings. I really hope they straighten out
this mess for Perl 6 (from what I have been reading it looks like they
have).
--
Today is Pungenday the 35th day of Discord in the YOLD 3168
Missile Address: 33:48:3.521N 84:23:34.786W
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]