but there is no real ambiguity in the first place, or is there?

Us humans can see the picture and deduce an intent to divide in this example, but it's not easy to write a program to do that. Perl decides when it sees the / whether the / is part of the argument list. Since / can start an argument list, Perl guesses it's part of the argument list. When it detects an error, Perl has no way of knowing if it's because the programmer screwed up the match operator or if it's because it guessed wrong. Of course, you could tell Perl the function takes no arguments.

sub func() { return 8 } print func / 4; # 2

+ and - are also tricky tokens.

sub foo { return 8 } print foo + 4; # 8 print foo(+4); # 8 print foo() + 4; # 12 sub bar() { return 8 } print bar + 4; # 12 print bar() + 4; # 12

There are problems with using prototypes, however. You should look into that before using them.

As a programmer, you should know that omitting the parens leads to this type of problem and consider missing parens as the source of problems.


In reply to Re: Unexpected parser error by ikegami
in thread Unexpected parser error by saintmike

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.