Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://618278]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2017-12-11 23:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (319 votes). Check out past polls.

    Notices?