In perl.git, the branch dagolden/scalar-term-prototype has been created
<http://perl5.git.perl.org/perl.git/commitdiff/a7afe2a3f62a2e0c2cef11636d33dfe1441c6634?hp=0000000000000000000000000000000000000000>
at a7afe2a3f62a2e0c2cef11636d33dfe1441c6634 (commit)
- Log -----------------------------------------------------------------
commit a7afe2a3f62a2e0c2cef11636d33dfe1441c6634
Author: David Golden <[email protected]>
Date: Sun Sep 12 20:26:43 2010 -0400
Add scalar term prototype
A new, "scalar term" prototype C<\.> has been added for use within a
C<\[]> backslash group. It permits any argument that does not match
another prototype and forces scalar context. A scalar term prototype
must always be the final character in a backslash group and it may not
be grouped with C<\*> or C<\$> to avoid ambiguity. Functions are
responsible for confirming that the argument is of the correct type.
For example, the following function accepts an array or array
reference argument:
sub size (\...@.]) {
die "Not an array or arrayref" unless ref $_[0] eq 'ARRAY';
return scalar @{ $_[0] };
}
This allows any of these invocations:
size @array;
size $arrayref;
size [1,2,3,4,5];
size array_ref();
-----------------------------------------------------------------------
--
Perl5 Master Repository