in reply to Strange behaviour when returning the value of "do {}" - possible perl bug?
This looks like a duplicate of "my" old bug #38809. If you turn warnings on, you'll notice that bar returns undef. This seems to have to do with the return context, since changing to return scalar do fixes the problem.use strict; use warnings; sub foo { if (1) { return do { 1; } } } sub bar { if (1) { return do { my $x; 1; } } } sub baz { if (1) { return scalar do { my $x; 1; } } } my $x = foo; my $y = bar; my $z = baz; print "#$x#\n"; print "#$y#\n"; print "#$z#\n";
|
|---|