On Thu, 11 Apr 2002, Damian Conway wrote:

> Piers wrote:
>
> > one could always handle the first case
> > more explicitly by doing:
> >
> >    sub load_data ($filename; $version) {
> >       $version = 1 if @_.length < 2;
> >       ...
> >    }
>
> Err...no. If you specify named parameters, you don't get @_.


        I'm a couple months behind on the discussion and haven't read
Apoc4 carefully yet, so my apologies if this has already been hashed out.

        Something I've always wished for in Perl (which of course I didn't
think of during the RFC period) was a way to have self-documenting
parameter names inside a function, but still maintain pass-by-reference
semantics, and do it all without fancy, hard-to-read aliasing tricks.
Ideally, I want something like:

        sub load_data ( \$filename; $version; @_ ) {
                $filename =~ s{/$}{};  # Affects $filename back in caller
                my $protocol = shift || 'html'; # shift defaults to @_
                ...
        }

        Note that here, $filename is pass-by-reference, $version is
pass-by-value, and, if extra arguments are passed, they will come in
through @_ so that I can still take advantage of the fact that most list
operators default to @_.  (Whether the contents of @_ are p-b-v or p-b-r
I'm not weighing in on.)

        Perhaps using \ in the signature to indicate p-b-r is not the
best...it could confuse people into thinking that they will need to
manually dereference the variable, which they shouldn't need to do.


        Is there a way to do this now?  If not, will there be a way in
Perl6?


Dave Storrs

Reply via email to