Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^2: Best Hash Practices?

by DamianKaelGreen (Acolyte)
on Oct 12, 2009 at 17:51 UTC ( #800761=note: print w/replies, xml ) Need Help??

in reply to Re: Best Hash Practices?
in thread Best Hash Practices?

Yes, this is the direction I was headed with this too... It would be nicer though if the input to the function was just the autovivified list of keys though, so we could maintain a more usual appearance, like:

print 6, isDefined($h{"a"}{2}{c}{4});

This is a kind of standard function that I think should be developed more thoroughly for everyone to use regularly; Either that, or the fundamentals of the way a multidimensional hash is handled should possibly be re-evaluated to recognize when something is being created vs when it's being tested...

Replies are listed 'Best First'.
Re^3: Best Hash Practices? (tie)
by LanX (Chancellor) on Oct 12, 2009 at 20:14 UTC

    I know what you mean but the syntax you're proposing is not feasible, since it's the arrow operator which is autovivifying!


    So when isDefined comes into action it's already to late!

    Anyway one can easily extend the syntax of my approach to make it "smoother"!

    xdefined(%h => qw/a 2 c 4/)


    xdefined(%h => "a",2,"c",4)

    But IMHO (within the boundaries of perl) the syntactically "prettiest" way to go would be to use a tied copy of your hash, like this you may be able to write


    %h2=novivi(%h) should be an empty hash with a hash-tie which mirrors safely the structure of %h.

    Such that $h2{a} is only be defined iff $h{a} is defined and all the automatically vivified structures in $h2{a}{2}{c}{4} are automatically tied hashes bound to the corresponding structures in %h.

    Well ... I think this is feasible, BUT should come with a significant performance penalty compared to my first approach, since ties are expensive.

    Cheers Rolf

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://800761]
[shmem]: LanX: now I have to find a succinct transformation FOOL => MONK
[LanX]: yeah but Marto already proposed a new "Lex Sun-D" ...
[karlgoethebier]: the word really exists: http://www. urbandictionary. com/define.php? term=fool
[shmem]: ...possibly involving RTFM
[karlgoethebier]: big surprise!
[Eily]: LanX I try to avoid answering, but I did feel that this one post was going into much detail to prove a false claim (that SHA-1 is secure, I was just wrong about how insecure it is)
[LanX]: ironically...
[LanX]: yeah whatever ... I'm in the favorable condition to already autohiding him ... how can I judge the poor FOOLs who still see his contributions xD
[Eily]: he's been pretty saavy about threads that were implictly about him in the past. I think he might have deliberatly avoiding mentioning it for some reason (he got tired?)
[Eily]: he did mention one of his propositions: basically make it possible to ignore downvotes, by separating them more from the upvotes

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2017-07-24 17:21 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (356 votes). Check out past polls.