On Tue, 21 Oct 2008 10:38:27 -0400, Jay Savage wrote: > On Thu, Oct 9, 2008 at 6:04 AM, Peter Scott <[EMAIL PROTECTED]> wrote: >> On Wed, 08 Oct 2008 04:59:19 -0700, John W. Krahn wrote: >>> perldoc perlsub >>> >>> To call subroutines: >>> >>> NAME(LIST); # & is optional with parentheses. >>> NAME LIST; # Parentheses optional if predeclared/imported. >>> &NAME(LIST); # Circumvent prototypes. >>> &NAME; # Makes current @_ visible to called subroutine. >> >> That isn't particularly relevant to the effect of leaving parentheses off >> method calls. You don't use & with methods (unless you're being >> perverse). Methods ignore prototypes. And @_ is not passed through when >> parens are left out on method calls. >> >> In fact, I can't find anything in perldoc about parens being optional on >> method calls. All the examples I find leave in even empty ones. Of >> course you can leave them out. Parenthesis-less calls are documented in >> the Camel ("Method Invocation") but not given any special attention. >> I guess that got added in the third edition when there started to be >> divergence between the Camel and perldoc. > > Actually, it's quite relevant. The important thing to remember is that > Perl has no inherent concept of objects or methods. Objects are just > subroutines that call bless() on themselves. The rules for passing > arguments to all subroutines apply to objects. The perlobj perldoc > also information on the "indirect object syntax" and how it applies, > in often quirky ways, specifically to method invocations.
Objects are not subroutines, they are references to blessed storage. The question was not about indirect method calls but using the arrow syntax (see subject). Perl may not have objects as tightly integrated into the language as other O-O languages, but it does have some of the principles baked in, in particular method calls. If it "had no inherent concept" of methods then $dog->eat( $kibble ) would be translated exactly to Dog::eat( $dog, $kibble ) But this is not the case if Dog inherits eat(). Perl knows about inheritance hierarchies, which counts as some form of concept of methods. The quoted section of perlsub did not address the original question of where it is documented that you can leave the parentheses off argumentless method calls. It's not the same as NAME LIST because method dispatch is handled quite differently from subroutine calls. See about halfway through perly.y. -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/