Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^3: Indirect Object Syntax

by haukex (Bishop)
on Nov 07, 2021 at 13:21 UTC ( #11138551=note: print w/replies, xml ) Need Help??

in reply to Re^2: Indirect Object Syntax
in thread Indirect Object Syntax

I've been reading this and realised that new is not a keyword in Perl!

Correct! Though it's generally considered polite to pay for those books than to read the pirated versions online (you may want to remove the link and replace it with a reference to the actual book).

Are these the accepted way to do it? Can they be imporved?

Yes, those are (syntactically) correct and best practice. They can be improved in the ways you showed:

Is it OK to condense that down to this and avoid the intermediate variable definition?

Yes, if you don't need the object - though some OO classes make a habit of returning the original object from some methods in order to explicitly allow method chaining, e.g. my $json = JSON::PP->new->ascii->pretty->allow_nonref;

Are the brackets necessary

No, they're not; IMHO it's fine to leave them off when there are no arguments (others might feel differently).

Replies are listed 'Best First'.
Re^4: Indirect Object Syntax
by Bod (Curate) on Nov 07, 2021 at 14:25 UTC

    Thanks haukex for your help

    you may want to remove the link and replace it with a reference to the actual book


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2022-05-22 01:59 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (78 votes). Check out past polls.