We don't bite newbies here... much | |
PerlMonks |
Re^7: Definition of numerically equal and rationale for 'you' == 'me'by moritz (Cardinal) |
on Mar 03, 2012 at 06:45 UTC ( [id://957612]=note: print w/replies, xml ) | Need Help?? |
I suppose the vast number of operators that Perl supports, compared to other languages, is made possible by sigils; that is, languages without sigils couldn't so easily use x or xx as an operator. Technically that's not quite correct. The really interesting property that makes that possible is predictive parsing. That is, the Perl parsers always knows whether to expect an infix operator or something termish (a prefix operator or a term, like for example a number, variable, subroutine call etc.). Even in an imaginary Perl without sigils, the following code could be parsed unambiguously:
The parser knows that say is a listop, and after that it expects a term. Thus the first x is term (here a variable), but since two terms in a row are forbidden, the next thing must be an infix operator (or maybe a semicolon to terminate the statement). Thus the second x is parsed as the repetition operator. And so on. Predictive parsing is also what makes it possible to use the slash / both as an infix operator, and as a regex delimiter. But even if it worked in theory, a sigil-less language with such a wealth of infix operators would probably be rather hard to read, and it would be much harder (if not impossible) to give good error messages in the case of syntax errors.
In Section
Seekers of Perl Wisdom
|
|