I've recently been reminded how much I hate the fact that C got the precedence for the bit-wise operators completely wrong (something which I believe at least one of Kernighan and Ritchie have publicly admitted to).
I know I'm way past the Perl 6 RFC process and this isn't the Perl 6 discussion list. But I wanted to throw this out here first...
Wouldn't it be great if Perl 6 were to fix this brain damage that has plagued (well, a somewhat minor plague) C, C++, Perl 4, and now Perl 5?
Here is how I'd prefer to have operator precedence table in Perl (note that I'm listing only Perl 5 operators even though I know these change will never make it into Perl 5):
| Associativity | Old | New |
|---|---|---|
| left | terms, (leftward) list ops | terms, (leftward) list ops |
| left | -> | -> |
| nonassoc | ++ -- | ++ -- |
| right | ** | ** |
| right | ! ~ \ unary + and - | ~ \ unary + and - |
| left | =~ !~ | =~ !~ |
| left | * / % x | * / % x |
| left | + - . | + - . |
| left | << >> | << >> |
| left | (n/a) | & |
| left | (n/a) | | ^ |
| nonassoc | named unary ops | named unary ops |
| nonassoc | < > <= >= lt gt le ge | < > <= >= lt gt le ge |
| nonassoc | == != <=> eq ne cmp | == != <=> eq ne cmp |
| left | & | (n/a) |
| left | | ^ | (n/a) |
| right | (n/a) | ! |
| left | && | && |
| left | || | || |
| nonassoc | .. ... | .. ... |
| right | ?: | ?: |
| right | = += -= *= etc. | = += -= *= etc. |
| left | , => | , => |
| nonassoc | (rightward) list ops | (rightward) list ops |
| right | not | not |
| left | and | and |
| left | or xor | or xor |
This preserves the relationship between the operators that you might already be mixing together, but removes the major breakedness of, for example, == binding tighter than &, |, and ^ so that you could finally just say: if( 0 == $mask & $value ) {
- tye (but my friends call me "Tye")
|
|---|