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

Re^3: Indirect Object Syntax

by haukex (Archbishop)
on Nov 07, 2021 at 13:21 UTC ( [id://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 (Parson) 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!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 12:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found