Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: eval order of args to a sub

by Tanktalus (Canon)
on May 30, 2007 at 18:55 UTC ( [id://618269]=note: print w/replies, xml ) Need Help??


in reply to eval order of args to a sub

I think the general rule of thumb is, "don't." As in, don't modify parameters to a function in the line that calls the function in such a way that could be confusing.

foo($i++); # ok foo(++$i); # ok foo($i,$i++); # not ok foo($i++,$i); # not ok foo($i++,++$i); # WTF?
If perl defined this, it would be one of very few languages that did so. And thus would still be confusing, IMO. It's not really that much extra work to avoid it. Use do if you have to:
my $flubber = do { my @args; push @args, $i++; push @args, ++$i; foo(@args) }; # well defined: $_[1] == $_[0]+2

Replies are listed 'Best First'.
Re^2: eval order of args to a sub
by shmem (Chancellor) on Jun 03, 2007 at 10:17 UTC
    Tanktalus++, best post in this thread: just "don't." And: avoid confusion.

    In that context I'd like to point at Quantum Weirdness and the Increment Operator, again, for a lengthy discussion of why modifying a variable more than one time via auto-{inc,dec}rement in the same statement is a very bad idea.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-19 08:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found