in reply to "last expression" quiz
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:sub x { for my $q (1..10) { print "$q\n"; } }
So the last expression evaluated is not @_forlist. Which is not explicit in the code!sub x { my @_forlist = (1..10); if (@_forlist) { do { my $q = pop @_forlist; print "$q\n"; } until ( not @_forlist ); } }
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
--
Quantum Mechanics: The dreams stuff is made of
|
|---|