Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wantarray docs should mention effect of eval { wantarray } #7211

Closed
p5pRT opened this issue Apr 2, 2004 · 4 comments
Closed

wantarray docs should mention effect of eval { wantarray } #7211

p5pRT opened this issue Apr 2, 2004 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Apr 2, 2004

Migrated from rt.perl.org#28171 (status was 'resolved')

Searchable as RT28171$

@p5pRT
Copy link
Author

p5pRT commented Apr 2, 2004

From @timbunce

This is a bug report for perl from Tim.Bunce@​pobox.com,


[Please enter your report here]

The wantarray docs don't mention that if wantarray is used inside an
eval { } block then it'll return the context for the block and not
the containing sub.

$ perl -l -we 'sub foo { eval { print (wantarray ? "list" : "scalar") };1 }; $a=foo; @​a=foo;'
scalar
scalar

$ perl -l -we 'sub foo { do { print (wantarray ? "list" : "scalar") };1 }; $a=foo; @​a=foo;'
scalar
list

@p5pRT
Copy link
Author

p5pRT commented Apr 5, 2004

From @rgs

Tim Bunce (via RT) wrote​:

The wantarray docs don't mention that if wantarray is used inside an
eval { } block then it'll return the context for the block and not
the containing sub.

I committed the following patchlet :

Change 22651 by rgs@​valis on 2004/04/05 11​:50​:10

  [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.

Affected files ...

... //depot/perl/pod/perlfunc.pod#432 edit
... //depot/perl/t/op/wantarray.t#4 edit

Differences ...

==== //depot/perl/pod/perlfunc.pod#432 (text) ====

@​@​ -6625,10 +6625,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 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();

==== //depot/perl/t/op/wantarray.t#4 (xtext) ====

@​@​ -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 @​@​
  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;

@p5pRT
Copy link
Author

p5pRT commented Apr 5, 2004

The RT System itself - Status changed from 'new' to 'open'

@p5pRT p5pRT closed this as completed Apr 5, 2004
@p5pRT
Copy link
Author

p5pRT commented Apr 5, 2004

@rgs - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant