Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Preventing autovivification

by EvanCarroll (Chaplain)
on Feb 16, 2010 at 04:43 UTC ( #823400=note: print w/ replies, xml ) Need Help??


in reply to Re: Preventing autovivification
in thread Preventing autovivification

In addition to this, you need to isolate the object (inside out) from the implementation (hash). In short, there is no way to stop an attribute from being added to a hash data structure. Auto-vivification is just part of the behavior of hashes.

You can achieve like-hashes that don't auto-vivify like this with Variable::Magic or Tie::HashRef, but I believe this to be outside the scope of the question.

With an inside hash, you would typically control autovivification with the set method.



Evan Carroll
The most respected person in the whole perl community.
www.evancarroll.com


Comment on Re^2: Preventing autovivification
Re^3: Preventing autovivification
by BrowserUk (Pope) on Feb 16, 2010 at 05:51 UTC
    In addition to this, you need to isolate the object (inside out) from the implementation (hash).

    Sorry, but I think you are compounding two different goals and coming up with a lemon.

    The original goals of IOOs were:

    • Proper encapsulation
    • Compile time checking of attribute use.
    • A technique not a module.
    • Don't depend on the implementation of the superclass.
    • Don't force a particular implementation on subclasses.
    • Simplicity.

    What you are suggesting is that the internal data implementation should be encapsulated (isolated) from the internal code. This was never a (stated) design goal, but can be achieved by the religious use of accessors, internally.

    In short, there is no way to stop an attribute from being added to a hash data structure. Auto-vivification is just part of the behavior of hashes.

    Actually, I think Hash::Util was specifically designed to address this.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (14)
As of 2014-08-27 19:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (250 votes), past polls