Perl anomalies 
Author Message
 Perl anomalies

Here's a random assortment from my Perl anomalies file.  Seen any good
anomalies lately?



        # the second is a semantic error.

(substr($x, 0, 1), substr($x, 3, 1)) = ('a', 'b');
        # semantic error.

($a, local($b)) = (2, 3);
        # semantic error.

substr($x = 'abc', 0, 1) = 'd';
substr(local($x) = 'abc', 0, 1) = 'd';
        # the second doesn't do what you expect.  a vector assignment
        # in a scalar context returns the vector's length.

$x = 3; $y = 4; ++($x, $y); print $x, $y;
        # prints nothing.

($a, $b) += (3, 4);
        # only does $b += 4.  $a is unchanged.

        # does nothing.

$a = *b = 'z';
        # sets $a to *z, rather than 'z'.  the value of a scalar
        # assignment is the lhs, not the rhs.

(1 ? $x : $y) = 5;
        # semantic error.

$x ? $y = 3 : $z = 4;
        # unlike C, this gets parsed as ($x ? $y = 3 : $z) = 4.

$x = (2, 3, 4,)[2];
        # the second is a syntax error.





$_ = '12345'; print length > 3;
$_ = '12345'; print length < 3;
        # the second doesn't do what you expect.
        # compare: print length < 3;>

while () {}
until () {}
        # the second is a syntax error.

while () {}
while (()) {}
while {} {}
1 while ();
        # the first is an infinite loop, the other three are not.

$_ = 1; print exp $_ % -1;
$_ = 1; print exp % -1;
        # the second doesn't do what you expect.
        # compare: print exp % ;



Sat, 02 Apr 1994 07:11:15 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. mod perl anomalies

2. Perl->CGI->Textarea anomaly

3. HTML::TokeParser Anomaly

4. Sarathy's vs. Activestate Anomaly

5. Anomaly when using OLE and File Upload

6. command line/system call anomaly

7. number->string anomaly

8. *glob anomaly

9. Anomaly with ~~ in format

10. equivalency anomaly

11. Interesting $$ anomaly?

12. file handle anomaly

 

 
Powered by phpBB® Forum Software