>>>>> "MGS" == Michael G Schwern <Michael> writes:

MGS> You've seen Mark Lentczner's Periodic Table of Perl 6 Operators
MGS> http://www.ozonehouse.com/mark/blog/code/PeriodicTable.html

MGS> What about one for Perl 5?
MGS> http://www.pobox.com/~schwern/tmp/perl5ops

MGS> So... did I miss anything?

"and" and "or" are the only ones that jump out at me. I think they
definitely deserve their own entries: subjectively, I'd say "&&" is
more different from "and" than "," is from "=>" or than """" is from
"qq//".

MGS> The big step is to work out operator precedence.  perlop has a 24
MGS> level precedence table but I suspect that's perhaps the biggest
MGS> white lie in all the Perl docs.  Can Perl 5 even be said to have
MGS> a simple enough idea of op precedence to apply a number to each
MGS> op?  If so, how does one go about figuring this out?

I think perlop's table covers it pretty well. Precedence doesn't
really make sense for "circumfix" things like parentheses and quotes,
but it's pretty well defined for prefix, infix, and postfix
operators. For function-like operators, you consider the case where
they're operating on exactly one argument. In general, you test the
precedence between two operators by setting up a fight and seeing
which one wins. In the classic infix-infix case, for instance, if you
want to see whether + or * has higher precedence, you write:

1 + 2 * 3

and see whether the answer is 9 or 7. The other combinations you can
test are

PREFIX arg INFIX arg

arg INFIX arg POSTFIX

and

PREFIX arg POSTFIX

Even if you can't think of an example that makes semantic sense, you
can often use -MO=Deparse,-p to see how Perl is doing its parsing. For
instance, to see that the precedence of "-r" is in between that of ">"
and that of ">", say:

% perl -MO=Deparse,-p -e '-r $x >> $y'
-r(($x >> $y));  # >> wins
% perl -MO=Deparse,-p -e '-r $x > $y'
(-r($x) > $y);   # -r wins

I've correlated your list with the levels used in B::Deparse (based on
perlop) here:

http://www.csua.berkeley.edu/~smcc/p5p-tmp/perl5ops-prec

 -- Stephen

Reply via email to