Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: to paren or not to paren

by kcott (Archbishop)
on Apr 26, 2014 at 06:01 UTC ( [id://1083896]=note: print w/replies, xml ) Need Help??


in reply to to paren or not to paren

G'day quixadhal,

When in doubt, you can check how Perl will parse your code fragment from the command line, rather than having to run a (test) script, with this:

perl -MO=Deparse,-p -e '... code fragment here ...'

See B::Deparse for more information about this.

"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." [my emphasis]

Clarification is exactly what's needed here. Perl doesn't know if you meant

$self->selector->remove($self)->listener;

or

$self->selector->remove($self->listener);

Notice in the following what's valid and invalid syntax:

$ perl -MO=Deparse,-p -e '$self->selector->remove $self->listener;' Scalar found where operator expected at -e line 1, near "->remove $sel +f" (Missing operator before $self?) syntax error at -e line 1, near "->remove $self" -e had compilation errors.
$ perl -MO=Deparse,-p -e '$self->selector->remove($self)->listener;' $self->selector->remove($self)->listener; -e syntax OK
$ perl -MO=Deparse,-p -e '$self->selector->remove($self->listener);' $self->selector->remove($self->listener); -e syntax OK

For more information about calling methods, see perlobj. In particular, these three sections of that documentation:

-- Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1083896]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-19 01:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found