Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Question regarding hash with multiple values

by BillKSmith (Vicar)
on Jul 10, 2013 at 13:59 UTC ( #1043477=note: print w/replies, xml ) Need Help??


in reply to Question regarding hash with multiple values

Here is an AoH solution.
use strict; use warnings; use Data::Dumper; my %celebs = ( 'Bob Dole' => { 'address' => '123 peach st.', 'spouse' => 'Bill Clinton', 'father' => 'Frank Dole' }, 'Al Pacino' => { 'address' => '123 orange st.', 'spouse' => 'Robert Deniro', 'father' => 'Marlon Brando' } ); my @people = map { { name => $_, address => $celebs{$_}{address}, spouse => $celebs{$_}{spouse}, father => $celebs{$_}{father}, } } keys %celebs; print Data::Dumper->Dump( [\@people],[qw(*people)] );
OUTPUT:
@people = ( { 'spouse' => 'Robert Deniro', 'father' => 'Marlon Brando', 'name' => 'Al Pacino', 'address' => '123 orange st.' }, { 'spouse' => 'Bill Clinton', 'father' => 'Frank Dole', 'name' => 'Bob Dole', 'address' => '123 peach st.' } );
Bill

Replies are listed 'Best First'.
Re^2: Question regarding hash with multiple values
by Skeeve (Vicar) on Jul 10, 2013 at 18:35 UTC
    I'd apply a small change:
    use strict; use warnings; use Data::Dumper; my %celebs = ( 'Bob Dole' => { 'address' => '123 peach st.', 'spouse' => 'Bill Clinton', 'father' => 'Frank Dole' }, 'Al Pacino' => { 'address' => '123 orange st.', 'spouse' => 'Robert Deniro', 'father' => 'Marlon Brando' } ); my @people = map { { name => $_, %{$celebs{$_}}, # <- Change is here } } keys %celebs; print Data::Dumper->Dump( [\@people],[qw(*people)] );
    So you don't need to "hard code" the celeb's keys.

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1043477]
help
Chatterbox?
[Corion]: marto: Oof - that means taking a day off or can you work from home?
[marto]: Corion, I can do some non-technical things, but there's no way for me to connect to the clients network.
[marto]: which is a shame, I had a really productive day yesterday
[Corion]: marto: Meh, so it'll be a day of cleaning out email...
[marto]: and hoped that I'd be able to continue the momentum :)
[marto]: I can't even access client email, nor my employers since those idiots moved to citrix
[marto]: it literally doesn't work. Also, via their citrix interface theres no way to open attachments, or upload an attachment for sending. The company policy is that you email you work account from a personal one, and forward it on from there :/

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2018-01-16 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (175 votes). Check out past polls.

    Notices?