Problems? Is your data what you think it is? | |
PerlMonks |
surprising backwards evaluation orderby fizbin (Chaplain) |
on Mar 17, 2006 at 20:03 UTC ( [id://537549]=perlquestion: print w/replies, xml ) | Need Help?? |
fizbin has asked for the wisdom of the Perl Monks concerning the following question: So in the process of getting enlightened about a syntax misunderstanding, I ran across this oddity: First, look at this code and ask yourself what you think it should produce:
No peaking; take a guess first That code produces
Now, I'm pretty sure we all agree that 7 has to be last, and obviously 2 must be printed later than both 3 and 4, and also 5 must be printed later than 6, but what about the rest? It appears that this order is the logical result of perl evaluating &{func }(args ) by evaluating args first, (left to right), and then evaluating func. This strikes me as an odd choice - it goes against the left-to-right evaluation order that perl follows elsewhere. (well, except for if and other control constructs at the end of a statement) Do any monks familiar with language implementation in general have any insight into why things are done that way? Note that an interesting consequence of this is that the following both die with the message "TWO":
--
Back to
Seekers of Perl Wisdom
|
|