develooper Front page | perl.perl5.porters | Postings from December 2004

[PATCH] Re: [perl #2562] wantarray fails in END, INIT, and CHECK blocks

Thread Next
From:
Mike Guy
Date:
December 10, 2004 11:08
Subject:
[PATCH] Re: [perl #2562] wantarray fails in END, INIT, and CHECK blocks
Message ID:
E1Ccq7V-00057s-9s@virgo.cus.cam.ac.uk
Steve Peters wrote
> In END, INIT, and CHECK, wantarry returns a PVNV.  Outside
> those functions, it returns NULL.

Those values are just the standard builtin values of 'true', 'false'
and 'undef', i.e. PL_sv_yes, PL_sv_no and PL_sv_undef.

I haven't looked at the original bug but I assume it is making some
some comment about the values of wantarray() in END{}.    But this is
a pretty stupid thing to worry about.    The answer is to document it
as not being specified, as in the attached patch.


Mike Guy

--- ./pod/perlfunc.pod.orig	2003-07-27 22:47:22.000000000 +0100
+++ ./pod/perlfunc.pod	2004-12-10 18:56:58.051871000 +0000
@@ -6530,15 +6530,19 @@
 
 =item wantarray
 
-Returns true if the context of the currently executing subroutine is
-looking for a list value.  Returns false if the context is looking
-for a scalar.  Returns the undefined value if the context is looking
-for no value (void context).
+Returns true if the context of the currently executing subroutine or
+C<eval> is looking for a list value.  Returns false if the context is
+looking for a scalar.  Returns the undefined value if the context is
+looking for no value (void context).
 
     return unless defined wantarray;	# don't bother doing more
     my @a = complex_calculation();
     return wantarray ? @a : "@a";
 
+C<wantarray()>'s result is unspecified in the top level of a file,
+in a C<BEGIN>, C<CHECK>, C<INIT> or C<END> block, or in a C<DESTROY>
+method.
+
 This function should have been named wantlist() instead.
 
 =item warn LIST

End of patch

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About