On Sat, Mar 22, 2008 at 1:39 AM, Joel <[EMAIL PROTECTED]> wrote:
> Thank you Rob.
>
> I am aware of that actually. To state my confusion, I wil get a better
> example:
>
>
> For the following code,
>
> sub fun {
> print "fun(@_) ";
> }
>
> fun 1, fun ''b" | "c", 1;
>
> The output looks like:
> fun(c,1) fun(1,1)
>
> *but* the precedence of the operators used is as: comma operator,
> list operator, bitwise string operator.
> *so* the commas and list operators should be evaluated before the pipe
> gets a chance.
> so the right hand side of the pipe is discarded, passing only "b" to
> the funciton because the list operator is evaluated before the pipe.
> But this doesn't seem to be happening!
snip
Look at the order of operations again*. The precedence in that expression is:
1. terms and list operators (leftward)
2. | ^
3. , =>
4. list operators (rightward)
The highest precedence is terms and list operators (leftward) and the
lowest is list operators (rightward). List operators have a higher
precedence than everything to their left, but a lower precedence than
everything but not, and, or, and xor to their right. So, If I place
parenthesis around each item to make it unambiguous it looks like
this:
(fun((1), (fun((("b") | ("c")), (1)))));
* http://perldoc.perl.org/perlop.html#Operator-Precedence-and-Associativity
left terms and list operators (leftward)
left −>
nonassoc ++ −−
right **
right ! ~ \ and unary + and −
left =~ !~
left * / % x
left + − .
left << >>
nonassoc named unary operators
nonassoc < > <= >= lt gt le ge
nonassoc == != <=> eq ne cmp
left &
left | ^
left &&
left ||
nonassoc .. ...
right ?:
right = += −= *= etc.
left , =>
nonassoc list operators (rightward)
right not
left and
left or xor
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/