Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Anonymous Hash in Constructor

by sundialsvc4 (Monsignor)
on Oct 18, 2012 at 20:25 UTC ( #999818=note: print w/ replies, xml ) Need Help??


in reply to Re: Anonymous Hash in Constructor
in thread Anonymous Hash in Constructor

Of course, a local-variable is “lost” too, as soon as the containing subroutine (the constructor ...) ends.   So in this case, it really is a matter of personal preference on the part of the author.   You’re going to create something, you might or might not twiddle with it, you’re going to bless it, and then you’re going to return it as the function-result.   Q.E.D.   As long as the meaning of the block of code which you use to do that is abundantly obvious, and effortlessly maintainable, “Feel Free.™”


Comment on Re^2: Anonymous Hash in Constructor
Re^3: Anonymous Hash in Constructor
by tobyink (Abbot) on Oct 19, 2012 at 10:39 UTC

    Indeed. The two sample constructors I provided are functionally identical. If the Perl compiler were smart enough, it could happily generate the same optree from each (but it currently does not).

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2014-07-31 03:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (244 votes), past polls