Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Equivalency of Code

by DrHyde (Prior)
on Feb 07, 2005 at 11:09 UTC ( #428625=note: print w/replies, xml ) Need Help??


in reply to Equivalency of Code

They are quite clearly not the same.
$x = 3; print $x++;
vs
$x = 3; print $x += 1;
Those two are only the same as regards their effect on $x. The expressions do not *evaluate* to be the same.

Replies are listed 'Best First'.
Re^2: Equivalency of Code
by adamk (Chaplain) on Feb 08, 2005 at 03:10 UTC
    No fair!

    HIS code didn't have print statements in it, he was using them as standalone statements. You are testing something different.
    $x = 3; $x++; print $x;
    vs
    $x = 3; $x += 1; print $x;
    ...would be more accurate.

    Of course, given problems with operator overloading, they stil arn't actually equal.
      The point is that $x++ and $x += 1 don't just fiddle with the value of $x. Those statements also have values themselves. If a bit of code is to be equivalent to another, then it needs to both have the same side-effects and the same value as the other does.

      I try not to think about operator overloading or tieing :-)

        The statements are presented where in void context - and in void context, there's no return value.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2021-10-18 15:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (74 votes). Check out past polls.

    Notices?