in reply to Doubt on defined-ness
So, if your last line is not terminated by a newline and is the string "0", you'll get tripped on this if don't for defined-ness.
Update: Considering the discussion below, I should have made it clear that this is a potential problem only for if statements (which is what the OP asked about), not while statements.
What is interesting is that even though the condition expression for while and if statements is executed in "boolean" context, the magic of the diamond operator only happens in while statements.
use strict; use warnings; use Contextual::Return; use Carp; while (foo()) { last; } while (my $x = foo()) { last; } if (foo()) { } if (my $z = foo()) { } sub foo { return BOOL { carp "BOOL"; 1; } SCALAR { carp "SCALAR"; 1; } ; } __END__ BOOL at ./cr line 6 BOOL at ./cr line 7 BOOL at ./cr line 8 BOOL at ./cr line 9
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Doubt on defined-ness
by moritz (Cardinal) on Jun 18, 2008 at 19:19 UTC | |
by FunkyMonk (Bishop) on Jun 18, 2008 at 19:35 UTC | |
by betterworld (Curate) on Jun 18, 2008 at 19:38 UTC | |
by tinita (Parson) on Jun 18, 2008 at 19:39 UTC | |
|
Re^2: Doubt on defined-ness
by waldner (Beadle) on Jun 18, 2008 at 19:15 UTC |