Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: eval order of args to a sub

by swampyankee (Parson)
on May 30, 2007 at 19:22 UTC ( #618278=note: print w/replies, xml ) Need Help??

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


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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://618278]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2018-09-20 02:15 GMT
Find Nodes?
    Voting Booth?
    Eventually, "covfefe" will come to mean:

    Results (170 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!