Parentheses and operators (is it me or is it the world?) 
Author Message
 Parentheses and operators (is it me or is it the world?)

Consider this program:

        $a=5;
        print (++$a=0);
        print " $a\n";

        $a=5;
        print ((++$a)=0);
        print " $a\n";

        $a=5;
        print (++($a=0));
        print " $a\n";

You'd expect the first and second groups to print "0 0" and the third "1 1",
right?  Wrong.  3.0.1.5 on a Sparc, 4.0.1.1 on a Vax, and 4.0.1.4 on a Sparc
all generate this output:

        0 6
        0 0
        1 1

Is this really how it's supposed to work?

--
% =(one,hacker,two,Just,three,another,four,Perl4);$,=' ';print values% ,"\n";



Fri, 01 Apr 1994 20:08:53 GMT  
 Parentheses and operators (is it me or is it the world?)
Ah yes, the ++/= anomaly.  Here's a simpler form of it:
        $x = 0; (++ $x) = 5;    # sets $x to 5.
        $x = 0; ++ ($x = 5);    # sets $x to 6.
        $x = 0; ++ $x = 5;      # sets $x to 1!

The last line should act like the first line, but the evaluator ends
up assigning 5 to a useless location.

I don't understand Perl's evaluator enough to provide a safe fix.
--



Sat, 02 Apr 1994 04:00:24 GMT  
 Parentheses and operators (is it me or is it the world?)
| Ah yes, the ++/= anomaly.  Here's a simpler form of it:
|       $x = 0; (++ $x) = 5;    # sets $x to 5.
|       $x = 0; ++ ($x = 5);    # sets $x to 6.
|       $x = 0; ++ $x = 5;      # sets $x to 1!
|
| The last line should act like the first line, but the evaluator ends
| up assigning 5 to a useless location.

I too believe that the last line should act like the first line, and
be illegal, to parallel C's interpretation.

The result of a ++ or -- is not an lvalue.

for ("Juss","anotheq","Perk","hackeq") { print ++$_, " "; } print "\b,";
--
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |

\=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/



Sat, 02 Apr 1994 04:45:24 GMT  
 Parentheses and operators (is it me or is it the world?)

Quote:

>The result of a ++ or -- is not an lvalue.

Hmm.  This is true in C, but Perl's grammar doesn't disallow it and
Perl doesn't complain about it, as it would if you said "3 = 4;".  It
just fails to work as you expect.

I don't see any reason why (++$x) shouldn't be an lvalue, but it
doesn't seem particularly useful.  Well, maybe double-post-increment
can be useful.
--



Sat, 02 Apr 1994 06:44:08 GMT  
 Parentheses and operators (is it me or is it the world?)

        Ah yes, the ++/= anomaly.  Here's a simpler form of it:
                $x = 0; (++ $x) = 5;    # sets $x to 5.
                $x = 0; ++ ($x = 5);    # sets $x to 6.
                $x = 0; ++ $x = 5;      # sets $x to 1!

        The last line should act like the first line, but the evaluator ends
        up assigning 5 to a useless location.

        I don't understand Perl's evaluator enough to provide a safe fix.

Ah yes, the 'try to get all in one statement anomaly'.  The safe
fix is that if it isn't obvious or the language could get
confused by the syntax, use separate statements!  Just because
the language will allow me to do something in one statement
doesn't mean I have to.  I don't know how many times I've shot
myself in the foot trying to get too cute with things like this.

Bill
--

UUCP:   ...!thebes!camco!bill   6641 East Mercer Way
             uunet!camco!bill   Mercer Island, WA 98040; (206) 947-5591
SPEED COSTS MONEY -- HOW FAST DO YOU WANT TO GO?



Sat, 02 Apr 1994 23:00:47 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. All computers in world MUST sync with ATOMIC clock before 12:00 AM 21July 2001

2. Who am I? What am I doing? (looking for input)

3. Class::Contract - what am I doing wrong?

4. ppm fails now that I am on perl 5.6

5. Closure and Lexicals: Am I confused?

6. Help hashes...... I am lost

7. I am still a Virgin!

8. newbie-perl or why am i blind to this simple

9. I am a perl beginner

10. I Am Very Sorry!!!

11. I am a beginner -- need some HELP!

12. CGI.pm - what am I doing wrng?

 

 
Powered by phpBB® Forum Software