Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Strange behaviour when returning the value of "do {}" - possible perl bug?

by Prof Vince (Friar)
on Nov 02, 2007 at 22:48 UTC ( #648736=note: print w/ replies, xml ) Need Help??


in reply to Strange behaviour when returning the value of "do {}" - possible perl bug?

Crossposted from p5p :

This reduces to :

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";
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.

Edit: When ran into taint mode, foo fails too.

Edit^2: Bah, exactly what kyle said !


Comment on Re: Strange behaviour when returning the value of "do {}" - possible perl bug?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://648736]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2015-07-04 00:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls