From: Rafael Garcia-Suarez Date: Mon, 5 Apr 2004 11:50:10 +0000 (+0000) Subject: [perl #28171] wantarray docs should mention effect of eval { wantarray } X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cc37eb0b599d134736fb6f123ae6520fdea588e3;p=p5sagit%2Fp5-mst-13.2.git [perl #28171] wantarray docs should mention effect of eval { wantarray } as reported by Tim Bunce. Add a note to this effect in perlfunc, and regression tests for it. p4raw-id: //depot/perl@22651 --- diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 2c368e9..3db7ca7 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 28936f4..350270d 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;