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

perlfunc wantarray() ambiguity

From:
Rich Lafferty
Date:
December 21, 2000 14:10
Subject:
perlfunc wantarray() ambiguity
Message ID:
20001221164354.C27961@alcor.concordia.ca
Hullo, porters.

I was just explaining contexts to someone, and the question arose as
to how to tell if a sub was called in scalar or void context. The
example for wantarray() suggests that it would be useful for this, and
as it turns out it *is* useful for this, but the documentation's
ambiguous (or I'm reading it as so).

Perhaps this would be clearer: 

============== cut here =================================
--- 5.6.0/perlfunc.pod.ORIG   Thu Dec 21 16:37:26 2000
+++ 5.6.0/perlfunc.pod        Thu Dec 21 16:41:26 2000
@@ -5690,10 +5690,10 @@
 
 =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 C<1> (true) if the context of the currently executing subroutine
+is looking for a list value.  Returns C<''> (defined but 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();
============== cut here =================================

   -Rich

-- 
------------------------------ Rich Lafferty ---------------------------
 Sysadmin/Programmer, Instructional and Information Technology Services
   Concordia University, Montreal, QC                 (514) 848-7625
------------------------- rich@alcor.concordia.ca ----------------------



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