Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by ikegami (Patriarch)
on Dec 23, 2010 at 21:28 UTC ( [id://878883]=note: print w/replies, xml ) Need Help??


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

An array of hashes whose elements are 'key' and 'value'.

It preserves the order of the pairs, and allows for duplicate keys. This structure would be useful for storing an HTML form, for example.

If you don't care about losing the order of the pairs, and you don't care about clobbering duplicate keys, you can flatten the structure using one of the following:

my %flattened; for (@data) { $flattened{ $_->{'key'} } = $_->{'value'}; }
my %flattened = map @{$_}{qw( key value )}, @data;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-18 23:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found