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

Re^2: The Bad, the Ugly, and the Good of autovivification

by Anonymous Monk
on Apr 08, 2005 at 12:18 UTC ( [id://446062]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: The Bad, the Ugly, and the Good of autovivification
in thread The Bad, the Ugly, and the Good of autovivification

Yeah, unfortunally, for algorithms that use 'exists', clamping hashes doesn't make sense. Either the key is known to be there (so, no need for exist), or its existance is volotile, which means that clamping hash prevent the keys from being inserted.

Sure, you can unclamp the hash whenever you insert a new key, but then it might be easier to write your exist test as:

$exists = exists $hash{key1} && exists $hash{key1}{key2};

Replies are listed 'Best First'.
Re^3: The Bad, the Ugly, and the Good of autovivification
by 5mi11er (Deacon) on Apr 09, 2005 at 01:44 UTC
    I don't think the first part of your argument is strictly true. If you use the @key's option, it would be possible for keys to not exist, or to be added dynamically, thus you might still need to see if that key happened to exist or not.

    However, you're correct that none of this stuff helps at all with respect to "auto-vivication". And your code example does appear to help work around the problem when dealing with nested structures.

    Hmm, Merlyn recently posted a snippet that walked a structure to it's leaf nodes, maybe we could combine the ideas of that snippet with this code to create a new form of exists?

    -Scott

    PS. the last paragraph was written "tongue-in-cheek", but it's late, and I would not be at all surprised to come into work on Monday to find someone actually wrote such a beast...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://446062]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.