Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Do you know where your variables are?
 
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 examining the Monastery: (13)
As of 2014-04-18 21:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (472 votes), past polls