develooper Front page | perl.perl5.porters | Postings from September 2013

Re: \@ and \% prototypes and slices

Thread Previous
From:
H.Merijn Brand
Date:
September 17, 2013 06:21
Subject:
Re: \@ and \% prototypes and slices
Message ID:
20130917082057.7e475824@pc09.procura.nl
On 16 Sep 2013 23:24:17 -0000, Father Chrysostomos <sprout@cpan.org>
wrote:

> I wrote:
> > It has never been clearly documented that \@ prototypes do not accept
> > slices.  Now that we have % slices, I thought it might be good to doc-
> > ument backslash prototypes more clearly.  But I fear my attempt may
> > make things too verbose.
> 
> The inline patch got totally screwed up.  lynx doesn’t like itwhen
> I paste tabs.  So here it is without tabs.  It will not apply as-is.

This makes a lot more sense! I threw away the first post as "this is
WAY out of my focus area"

> diff --git a/pod/perlsub.pod b/pod/perlsub.pod
> index 2b4b35b..4c99a9e 100644
> --- a/pod/perlsub.pod
> +++ b/pod/perlsub.pod
> @@ -1230,13 +1230,44 @@ corresponding built-in.
>     sub myrand (;$)           myrand 42
>     sub mytime ()           mytime
>  
> -Any backslashed prototype character represents an actual argument
> -that must start with that character (optionally preceded by C<my>,
> -C<our> or C<local>), with the exception of C<$>, which will
> -accept any scalar lvalue expression, such as C<$foo = 7> or
> -C<< my_function()->[0] >>. The value passed as part of C<@_> will be a
> +A backslashed prototype character expects its argument to
> +be a variable or dereference of the given type, with the
> +exception of C<$>, which will accept any scalar lvalue
> +expression. The value passed as part of C<@_> will be a
>  reference to the actual argument given in the subroutine call,
> -obtained by applying C<\> to that argument.
> +obtained by applying C<\> to that argument.  Examples of valid (and some
> +invalid) arguments include:
> +
> +    \*          *foo
> +                local *foo
> +                *$ref
> +                *{ func() }
> +
> +    \&          &foo
> +                &$coderef
> +                &{ $coderef }
> +
> +    \%          %foo
> +                my %foo
> +                %$foo
> +                %{ $foo }
> +                %array[$slice] # invalid; not a hash
> +                %hash{slice}   # invalid; not a hash
> +
> +    \@          @foo
> +                my @foo
> +                @$foo
> +                @{ $foo }
> +                @array[$slice] # invalid; not an array
> +                @hash{slice}   # invalid; not an array
> +
> +    \$          $x
> +                my $x
> +                $$x
> +                ${ $x }
> +                $foo = 7                # any lvalue is permitted
> +                my_function()->[0]      # including array
> +                ( $hashes[0] )->{foo}   # and hash elements
>  
>  You can use the C<\[]> backslash group notation to specify more than one
>  allowed argument type. For example:
> 


-- 
H.Merijn Brand  http://tux.nl   Perl Monger  http://amsterdam.pm.org/
using perl5.00307 .. 5.19   porting perl5 on HP-UX, AIX, and openSUSE
http://mirrors.develooper.com/hpux/        http://www.test-smoke.org/
http://qa.perl.org   http://www.goldmark.org/jeff/stupid-disclaimers/

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