The anonymonk above is correct. Perl's lexer doesn't expect an operator in this position (although it can handle "unexpected" operators). And this is done in the lexer, not the parser. Specifically, in Perl_yylex (toke.c):
case '/': /* may be division, defined-or, or pattern */ if ((PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR) && + s[1] == '/') { ... AOPERATOR(DORDOR); } else if (PL_expect == XOPERATOR) { ... Mop(OP_DIVIDE); } else { ... s = scan_pat(s,OP_MATCH); }
I'm no expert in how the lexer works but implementing parsing on such heuristics is a fragile thing.
Oh yes, Perl's lexer is fascinating :) I'm not an expert either, life is too short...

For example, you said that the concat op works...

case '.': ... if (PL_expect == XOPERATOR || !isDIGIT(s[1])) { ... Aop(OP_CONCAT)
So, if the lexer doesn't expect an operator, it decides based on whether the next character is a digit... Let's see:
$ perl -MO=Deparse -e 'sub foo(&) {}; foo { "foo" } . 5' sub foo (&) { } foo(sub { 'foo'; } ) . 5; -e syntax OK $ perl -MO=Deparse -e 'sub foo(&) {}; foo { "foo" } .5' Too many arguments for main::foo at -e line 1, at EOF -e had compilation errors. sub foo (&) { } &foo(sub { 'foo'; } , 0.5);
but:
$ perl -E 'say 1 .5' 15
because here it does expect an operator.

So, yeah... Just don't think too much about it :)

Hopefully this can be fixed in the future.
That would require fixing the grammar of the Perl 5 programming language; the major version surely should be incremented then and the backwards-incompatible result should be called Perl 6... oh wait...

In reply to Re: BUG when parsing defined-or ? by Anonymous Monk
in thread BUG when parsing defined-or ? by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.