Re: [PATCH] return values reworded in perlsub.pod
authorXavier Noria <fxn@hashref.com>
Fri, 21 Oct 2005 08:43:12 +0000 (10:43 +0200)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Fri, 21 Oct 2005 13:01:26 +0000 (13:01 +0000)
Message-Id: <1C8D7C5C-986C-4336-8C4F-8B965CE1AD17@hashref.com>

(with minor tweaks)

p4raw-id: //depot/perl@25812

pod/perlsub.pod

index fbf27cd..9711ca6 100644 (file)
@@ -73,16 +73,19 @@ Assigning to the whole array C<@_> removes that aliasing, and does
 not update any arguments.
 X<subroutine, argument> X<argument> X<@_>
 
-The return value of a subroutine is the value of the last expression
-evaluated by that sub, or the empty list in the case of an empty sub.
-More explicitly, a C<return> statement may be used to exit the
-subroutine, optionally specifying the returned value, which will be
-evaluated in the appropriate context (list, scalar, or void) depending
-on the context of the subroutine call.  If you specify no return value,
-the subroutine returns an empty list in list context, the undefined
-value in scalar context, or nothing in void context.  If you return
-one or more aggregates (arrays and hashes), these will be flattened
-together into one large indistinguishable list.
+A C<return> statement may be used to exit a subroutine, optionally
+specifying the returned value, which will be evaluated in the
+appropriate context (list, scalar, or void) depending on the context of
+the subroutine call.  If you specify no return value, the subroutine
+returns an empty list in list context, the undefined value in scalar
+context, or nothing in void context.  If you return one or more
+aggregates (arrays and hashes), these will be flattened together into
+one large indistinguishable list.
+
+If no C<return> is found and if the last statement is an expression, its
+value is returned. Otherwise, if the last statement is a control structure
+like a C<foreach>, the returned value is unspecified. The empty sub
+returns the empty list.
 X<subroutine, return value> X<return value> X<return>
 
 Perl does not have named formal parameters.  In practice all you