$ perl -Mstrict -le 'print "one" if (my $d = "1") && $d'
[or indeed if ((my $d = "1") && $d) {...} ]
perl apparently doesn't consider $d exists by the second $d and issues
an error. Can someone explain this? (Esp. in light of all this sequence
point talk.)
perldoc perlsub says,
The "my" operator declares the listed variables to be lexically con-
fined to the enclosing block, conditional ("if/unless/elsif/else"),
loop ("for/foreach/while/until/continue"), subroutine, "eval", or
"do/require/use"'d file.
This doesn't sound to me like it unequivocably explains the above.
for (my $i = 0; $i < 10; $i++) { works, for example. I'm assuming those
aren't "real" semi-colons.
Any suggestions/hacks how to get around this gratefully received: I
have a nasty chain of elsifs and I'd like to get a tmp variable into
the last conditional without declaring it miles away... (or re-writing
the logic, heh :-)
Paul
PS One hack I suppose is using $a or $b but that's just a little too
evil.
--
Paul Makepeace ....................................... http://paulm.com/
"What is the last man standing? Two cabbages and a giraffe."
-- http://paulm.com/toys/surrealism/