Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^13: the annoying keys "key" and "value"

by ikegami (Patriarch)
on Dec 24, 2010 at 04:33 UTC ( [id://878949]=note: print w/replies, xml ) Need Help??


in reply to Re^12: the annoying keys "key" and "value"
in thread the annoying keys "key" and "value"

So why would someone try to represent a hash with an array of two element hashes each with the keys "key" and "value"?

"Represent a hash" makes no sense. I presume you mean "implement an associative array".

Someone would do that if they wanted to preserve the order of the tuples. We've covered this multiple times already.

Replies are listed 'Best First'.
Re^14: the annoying keys "key" and "value"
by jabowery (Beadle) on Dec 24, 2010 at 06:32 UTC
    So you want to have an ordered associative array by using: [{'key'=>somekey1,'value'=>somevalue1},...] because that is superior to having: $order=[somekey1,somekey2,...]; and {somekey1=>somevalue1,...} ?

    Is this because using the associative array for its primary function -- looking up values from keys -- is so much more convenient and efficient your way?

      It's not a question of efficiency, it's a question of actually working. $order=[somekey1,somekey2,...]; and {somekey1=>somevalue1,...} doesn't support more than one value with the same key.

        For clarity, what you are calling an ordered associative array is actually an ordered relation. The definition of "associative array" is functional (ie: one value per key), not relational (ie: potentially N values per key). So we have:
        <ordered_relation_foo> <b>2</b> <b>4</b> <a>1</a> <b>6</b> <a>3</a> <a>5</a> </ordered_relation_foo>
        becomes:
        $ordered_relation_foo={ _meta_order=>[b,b,a,b,a,a], b=>[2,4,6], a=>[1,3,5]};
        So now a query of this ordered relation becomes:
        $ordered_relation_foo{a}
        How does that compare to the query of your structure?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-03-29 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found