summaryrefslogtreecommitdiff
path: root/pod/perlsub.pod
diff options
context:
space:
mode:
authorDavid Golden <dagolden@cpan.org>2010-09-12 20:26:43 -0400
committerDavid Golden <dagolden@cpan.org>2010-10-21 09:23:58 -0400
commitc035a075a240f10383292128a8d3f3746c4ac857 (patch)
treea245d8f117b9636fe740448118a753e5457978c8 /pod/perlsub.pod
parent9061a8f72941979d02cbccb5cb18a2034813b6a7 (diff)
downloadperl-c035a075a240f10383292128a8d3f3746c4ac857.tar.gz
Add single-term prototype
The C<+> prototype is a special alternative to C<$> that will act like C<\[@%]> when given a literal array or hash variable, but will otherwise force scalar context on the argument. This is useful for functions which should accept either a literal array or an array reference as the argument: sub smartpush (+@) { my $aref = shift; die "Not an array or arrayref" unless ref $aref eq 'ARRAY'; push @$aref, @_; } When using the C<+> prototype, your function must check that the argument is of an acceptable type.
Diffstat (limited to 'pod/perlsub.pod')
-rw-r--r--pod/perlsub.pod18
1 files changed, 16 insertions, 2 deletions
diff --git a/pod/perlsub.pod b/pod/perlsub.pod
index 149a8a71d1..c16db28937 100644
--- a/pod/perlsub.pod
+++ b/pod/perlsub.pod
@@ -1100,8 +1100,8 @@ C<< my_function()->[0] >>. 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.
-You can also backslash several argument types simultaneously by using
-the C<\[]> notation:
+You can use the C<\[]> backslash group notation to specify more than one
+allowed argument type. For example:
sub myref (\[$@%&*])
@@ -1136,6 +1136,20 @@ follows:
...
}
+The C<+> prototype is a special alternative to C<$> that will act like
+C<\[@%]> when given a literal array or hash variable, but will otherwise
+force scalar context on the argument. This is useful for functions which
+should accept either a literal array or an array reference as the argument:
+
+ sub smartpush (+@) {
+ my $aref = shift;
+ die "Not an array or arrayref" unless ref $aref eq 'ARRAY';
+ push @$aref, @_;
+ }
+
+When using the C<+> prototype, your function must check that the argument
+is of an acceptable type.
+
A semicolon (C<;>) separates mandatory arguments from optional arguments.
It is redundant before C<@> or C<%>, which gobble up everything else.