quixadhal has asked for the wisdom of the Perl Monks concerning the following question:
That is the question!
I've recently dug back into writing some object oriented perl code, and one annoyance I've discovered is a bit surprising. I was wondering if someone can explain this to me.
In most cases, I find I can happily write code which calls functions without needing to use those pesky parenthesis, other than to clarify which arguments are being passed, and which are part of another expression.
However, in some cases, and it seems more often when using methods via $self, the perl parser frowns upon what (to me) seems an obvious case of wanting to call a method and pass an argument.
This yields the error:$self->selector->remove $self->listener;
But if I add parens to that call, like thisScalar found where operator expected at Mud/Comm.pm line 149, near "-> +remove $self" (Missing operator before $self?) syntax error at Mud/Comm.pm line 149, near "->remove $self"
$self->selector->remove($self->listener);
Perl is content and all is well.
So my question boils down to... under what conditions can you omit the function calling parenthesis, and when MUST you use them?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: to paren or not to paren
by eyepopslikeamosquito (Archbishop) on Apr 26, 2014 at 08:43 UTC | |
by Jim (Curate) on Apr 28, 2014 at 03:52 UTC | |
|
Re: to paren or not to paren
by kcott (Archbishop) on Apr 26, 2014 at 06:01 UTC | |
|
Re: to paren or not to paren
by tobyink (Canon) on Apr 26, 2014 at 07:44 UTC | |
|
Re: to paren or not to paren
by wjw (Priest) on Apr 26, 2014 at 05:53 UTC | |
|
Re: to paren or not to paren
by Anonymous Monk on Apr 28, 2014 at 03:57 UTC |