The stupid question is the question not asked | |
PerlMonks |
Re: "last expression" quizby QM (Parson) |
on Oct 21, 2005 at 14:03 UTC ( [id://501999]=note: print w/replies, xml ) | Need Help?? |
Regarding the for loop issues (and this may apply to other loop controls as well), it seems that the loop must stop on a false boolean expression. If that's the last expression in the sub, then that should be returned.
Note that under the hood, all of the loop constructs can be mapped to a single generic construct (which I suspect is what actually happens). Suppose we have this: While you may think the last thing evaluated is print "$q\n", the for actually has to check that there are no more elements in the list, perhaps making the above code equivalent to: So the last expression evaluated is not @_forlist. Which is not explicit in the code! Most of the errant behaviors documented in this thread seem to ignore this implicit expression. Perhaps the documentation could emphasize that "last expression" doesn't mean "last explicit expression". BTW, does someone have the skills to investigate the optree for examples like these? -QM
In Section
Seekers of Perl Wisdom
|
|