http://qs321.pair.com?node_id=11138551


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

    Done!