http://www.perlmonks.org?node_id=618278


in reply to eval order of args to a sub

Evaluation order of arguments to a subroutine? One in a module, an intrinsic, or what?

Perl passes arguments to a subroutine as a list (see perlsub); the order in which the arguments are processed is dependent on how the subroutine is written. So, unless you've got access to the routine's source (or the routine is properly documented), I would not assume any particular order (although it's probably left to right, as mentioned in Re^7: finding number of contiguous letters by blazar).

Also, with my limited imagination, I can't conceive of a case where this matters and it's somewhere in the realm of what I've been taught as "good coding practice;" it reveals too much about the sub's internals.


punctuation correction

emc

Any New York City or Connecticut area jobs? I'm currently unemployed.

There are some enterprises in which a careful disorderliness is the true method.

—Herman Melville

Replies are listed 'Best First'.
Re^2: eval order of args to a sub
by dewey (Pilgrim) on May 30, 2007 at 19:36 UTC
    I'm having trouble imagining a sub that controls the order of evaluation of its 'parameters'; that sort of control of execution feels like it requires macros. Could you give me an example? For instance, two subs first and second such that
    first(print('a'), print('b')) # prints 'ab' second(print('a'), print('b')) # prints 'ba'
    To me, this whole thing feels like a misunderstanding. Each sub receives one list value as an argument. We're not passing in expressions to be evaluated or anything like that.

    ~dewey