Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Auto Increment "magic" Inquiryby GrandFather (Saint) |
on Jan 04, 2007 at 22:16 UTC ( [id://593033]=note: print w/replies, xml ) | Need Help?? |
Point B is the key. Point C is tricky. The assertion that "++$i was performed on first, then $i++" is misleading. The distinction would only be relevant for ++$i++ which is illegal in any case. In the expression $i++ + --$i neither Perl nor C make any promises about the order in which the two sub expressions are evaluated. The second paragraph of Section A7 in "The C Programming Language (second edition)" (the K&R C book) makes that absolutely clear in the case of C (and assists in understanding the issue in Perl): "... unless the definition of an operator guarantees that its operands are evaluated in a particular order, the implementation is free to evaluate operands in any order." On the basis of that statement alone any of your tests involving addition are spurious. In particular note (from the same paragraph as cited above): "... the order of evaluation of expressions is, with certain exceptions, undefined, even if the subexpressions involve side effects." (emphasis added) Your colleague is either lucky or experienced with the particular implementation you are using. Watch out for changes between versions, platforms, C compiler and compiler options - one day you are going to get bit, and it will be particuarly nasty to diagnose! Update: clarified the absolute clarity DWIM is Perl's answer to Gödel
In Section
Seekers of Perl Wisdom
|
|