Re: Table of Perl 5 Operators
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
Re: Table of Perl 5 Operators
On Tue, May 17, 2005 at 04:38:08PM -0700, Stephen McCamant wrote: and and or are the only ones that jump out at me. Thanks, a simple oversight. 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 Excellent, thank you. I've got a little web app nearly finished which will catalog all this and allow it to be modified and corrected. -- Michael G Schwern [EMAIL PROTECTED] http://www.pobox.com/~schwern You are wicked and wrong to have broken inside and peeked at the implementation and then relied upon it. -- tchrist in [EMAIL PROTECTED]
Re: Table of Perl 5 Operators
* Michael G Schwern ([EMAIL PROTECTED]) wrote: So... did I miss anything? Should //= be in there? Because my perl 5.8.6 doesn't seem to have it... -- Jose Alves de Castro [EMAIL PROTECTED] http://jose-castro.org/
Re: Table of Perl 5 Operators
On Wed, May 18, 2005 at 10:39:49AM +0100, Jos? Castro wrote: * Michael G Schwern ([EMAIL PROTECTED]) wrote: So... did I miss anything? Should //= be in there? Because my perl 5.8.6 doesn't seem to have it... It's in 5.9.x, or you can add it to 5.8.6 with this patch: http://perl.com/CPAN/authors/id/H/HM/HMBRAND/dor-5.8.6.diff
Re: Table of Perl 5 Operators
He! Nice colection. Now, anybody up to DRAW the table? :) Michael G Schwern wrote: You've seen Mark Lentczner's Periodic Table of Perl 6 Operators http://www.ozonehouse.com/mark/blog/code/PeriodicTable.html What about one for Perl 5? Using perlop, opcode.pl and Mark's table I've done step one: drawn up a complete list of Perl 5 operators. All 129 of them [1] in no particular order. http://www.pobox.com/~schwern/tmp/perl5ops I've followed Mark's lead as to what is and is not an op. The -X filetest operators, despite being in perlfunc, are ops. scalar is listed to match up with Mark's Contextegens. ref, exists, delete, etc... are listed to match up with the Textaveries. sub is not an op, that's syntax... I guess. I've asked Mark what his system was for deciding what is an what is not an op but it seems fairly sensible to me. So... did I miss anything? The big step is to work out operator precedence. perlop has a 24 level precedence table but I suspect that's perhaps the biggest white lie in all the Perl docs. Can Perl 5 even be said to have a simple enough idea of op precedence to apply a number to each op? If so, how does one go about figuring this out? [1] Mark's table shows 180 ops, but its a year out of date. If we remove the bitwise operators we get 153 for Perl 6 and 123 for Perl 5 and things start to look more sane. -- Alberto Simões - Departamento de Informática - Universidade do Minho Campus de Gualtar - 4710-057 Braga - Portugal