Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Question regarding hash with multiple values

by BillKSmith (Deacon)
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


Comment on Re: Question regarding hash with multiple values
Select or Download Code
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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2015-07-04 09:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (59 votes), past polls