in reply to order of evaluation of operands

I can answer this with much zeal and vigor. (Or I just wanted to use those two words.)

Use the B::Terse module, I made the following check:
jeffp@friday [10:44am] parsers #264> perl -MO=Terse sub a { print 1 } sub b { print 2 } $c = a() + b(); - syntax OK LISTOP (0x13b940) pp_leave OP (0x130ef8) pp_enter COP (0x13b970) pp_nextstate BINOP (0x142ce0) pp_sassign BINOP (0x142d00) pp_add [3] UNOP (0x142c20) pp_entersub [1] UNOP (0x13b9d0) pp_null [141] OP (0x130f58) pp_pushmark UNOP (0x142c40) pp_null [17] GVOP (0x142c60) pp_gv GV (0x12dbac) *a UNOP (0x142d20) pp_entersub [2] UNOP (0x13ba90) pp_null [141] OP (0x130f70) pp_pushmark UNOP (0x142d40) pp_null [17] GVOP (0x142d60) pp_gv GV (0x14bbc4) *b UNOP (0x12ea00) pp_null [15] GVOP (0xbed00) pp_gvsv GV (0xc6304) *c
Yes, Perl will call a() before it calls b(). That's why you can safely say: ($a,$b) = (shift, shift) to get the first two values from @_, IN THE RIGHT ORDER. (But you'd use splice(), really.)

Replies are listed 'Best First'.
RE: Re: order of evaluation of operands
by jlistf (Monk) on Jul 21, 2000 at 21:00 UTC
    That's why you can safely say: ($a,$b) = (shift, shift) to get the first two values from @_, IN THE RIGHT ORDER.
    the comma operator is one that definitely evaluates left to right. it does this even in C/C++ (in addition to &&, and, ||, or and ?:). i know that those evaluate left to right. but are all operators guaranteed to evaluate left to right. just because your computer does it that way does not necesarily mean that all will. granted Perl has less computer/software dependant items like C and C++, but i'd like to know for sure what the case is. preferably some mention in documentation or an answer from someone who's read the source code or a link to a tutorial or something.
      Check the perlop documentation.