summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pod/perlfunc.pod8
-rwxr-xr-xt/op/wantarray.t12
2 files changed, 15 insertions, 5 deletions
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index 2c368e9c71..3db7ca77ba 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -6625,10 +6625,10 @@ and for other examples.
=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
+eval() block 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();
diff --git a/t/op/wantarray.t b/t/op/wantarray.t
index 28936f419c..350270d11c 100755
--- a/t/op/wantarray.t
+++ b/t/op/wantarray.t
@@ -1,6 +1,6 @@
#!./perl
-print "1..9\n";
+print "1..12\n";
sub context {
my ( $cona, $testnum ) = @_;
my $conb = (defined wantarray) ? ( wantarray ? 'A' : 'S' ) : 'V';
@@ -31,4 +31,14 @@ $a = scalar context('S',5);
print +($c == 2) ? "ok 9\n" : "not ok 9\t# <$c>\n";
}
+my $qcontext = q{
+ $q = (defined wantarray) ? ( wantarray ? 'A' : 'S' ) : 'V';
+};
+eval $qcontext;
+print $q eq 'V' ? "ok 10\n" : "not ok 10\n";
+$a = eval $qcontext;
+print $q eq 'S' ? "ok 11\n" : "not ok 11\n";
+@a = eval $qcontext;
+print $q eq 'A' ? "ok 12\n" : "not ok 12\n";
+
1;