Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Puzzling $| behavior

by Anonymous Monk
on Oct 08, 2007 at 07:24 UTC ( #643411=note: print w/ replies, xml ) Need Help??


in reply to Puzzling $| behavior

Just for fun, try this:
$x=0; printf "%d %d %d\n",$x--,$x--,$x--;
Then try the same code (syntax adjusted) in any other language that supprts printf, like C. You will get different answers depending on the implementation. Some compilers give gifferent results depending on optimisation switches (Visual Studio, not gcc).
A good reason not to nest ++ or -- in other statements?

Replies are listed 'Best First'.
Re^2: Puzzling $| behavior
by ikegami (Pope) on Oct 08, 2007 at 07:37 UTC

    The OP's problem is not (just) due to the order in which the operands are executed (left to right). Try

    $x=0; printf "%d %d %d\n",$x,$x--,$x;

    Note that even though Perl executed the four operand from left to right, the result is -1 -1 -1.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2016-07-24 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?


















    Results (221 votes). Check out past polls.