note
haukex
<blockquote><i>I've been reading this and realised that <c>new</c> is not a keyword in Perl!</i></blockquote>
<p>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 [https://www.oreilly.com/library/view/learning-perl-objects/0596004788/|actual book]).</p>
<blockquote><i>Are these the accepted way to do it? Can they be imporved?</i></blockquote>
<p>Yes, those are (syntactically) correct and best practice. They can be improved in the ways you showed:</p>
<blockquote><i>Is it OK to condense that down to this and avoid the intermediate variable definition?</i></blockquote>
<p>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. <c>my $json = JSON::PP->new->ascii->pretty->allow_nonref;</c></p>
<blockquote><i>Are the brackets necessary</i></blockquote>
<p>No, they're not; IMHO it's fine to leave them off when there are no arguments (others might feel differently).</p>
11138524
11138549