'|' is left associative, and the left argument is evaluated first
Left-associative means that
is equivalent toa | b | c
and not( a | b ) | c
a | ( b | c )
It says nothing about the order in which a, b and c are evaluated in relation to each other. In fact, the operand evaluation order is undefined for most Perl operators including the "|" operator.
Perl is free to evaluate
as follows:a | b | c
push @stack, c; push @stack, b; push @stack, a; push @stack, pop(@stack) | pop(@stack); push @stack, pop(@stack) | pop(@stack); pop @stack;
The left pipe is evaluated before the right pipe, so the operator is left-associative, but note how c is evaluated before b, which is evaluated before a.
Your code is relying on undefined functionality. It's not guaranteed to work. You'd have to switch to || if you wanted predictable results. || is guaranteed to evaluate its LHS argument before its RHS argument due to its short-circuiting nature.
That's the official line, anyway. In reality, |'s LHS arg is always evaluated before its RHS, and I don't see that ever changing.
In reply to Re: Functional Composition
by ikegami
in thread Functional Composition
by billh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |