Here's the (HTML-ized) warning from perlop. Note the word "exclusively" at the end:

WARNING

While indirect object syntax may well be appealing to English speakers and to C++ programmers, be not seduced! It suffers from two grave problems.

The first problem is that an indirect object is limited to a name, a scalar variable, or a block, because it would have to do too much lookahead otherwise, just like any other postfix dereference in the language. (These are the same quirky rules as are used for the filehandle slot in functions like "print" and "printf".) This can lead to horribly confusing precedence problems, as in these next two lines:

move $obj->{FIELD}; # probably wrong! move $ary[$i]; # probably wrong!

Those actually parse as the very surprising:

$obj->move->{FIELD}; # Well, lookee here $ary->move->[$i]; # Didn't expect this one, eh?

Rather than what you might have expected:

$obj->{FIELD}->move(); # You should be so lucky. $ary[$i]->move; # Yeah, sure.

The left side of "->" is not so limited, because it's an infix operator, not a postfix operator.

As if that weren't bad enough, think about this: Perl must guess (at compile time) whether name and move above are functions or methods. Usually Perl gets it right, but when it doesn't it, you get a function call compiled as a method, or vice versa. This can introduce subtle bugs that are hard to unravel. For example, calling a method "new" in indirect notation--as C++ programmers are so wont to do--can be miscompiled into a subroutine call if there's already a "new" function in scope. You'd end up calling the current package's "new" as a subroutine, rather than the desired class's method. The compiler tries to cheat by remembering bareword "require"s, but the grief if it messes up just isn't worth the years of debugging it would likely take you to to track such subtle bugs down.

The infix arrow notation using "->" doesn't suffer from either of these disturbing ambiguities, so we recommend you use it exclusively.


In reply to Re: (cLive ;-) Re: Perl High School by quikwit
in thread Perl High School by hsweet

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.