aartist has asked for the wisdom of the Perl Monks concerning the following question:
From:
To,my $var = [ { 'city' => 'New York', 'name' => 'Bill' }, { 'city' => 'New York', 'name' => 'Ronald' }, { 'city' => 'Boston', 'name' => 'George' } ];
My attempt:$VAR1 = { 'New York' => [ 'Bill', 'Ronald' ], 'Boston' => [ 'George' ] };
Thanks.map { push @{$var1->{$_->{city}}}, $_->{name} } @{$var};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Data Structure Transformation
by wind (Priest) on Jan 31, 2011 at 20:07 UTC | |
|
Re: Data Structure Transformation
by GrandFather (Saint) on Jan 31, 2011 at 20:32 UTC | |
by Anonymous Monk on Jan 31, 2011 at 21:18 UTC | |
|
Re: Data Structure Transformation
by ELISHEVA (Prior) on Jan 31, 2011 at 21:17 UTC | |
|
Re: Data Structure Transformation
by roboticus (Chancellor) on Feb 01, 2011 at 00:03 UTC | |
|
Re: Data Structure Transformation
by planetscape (Chancellor) on Feb 01, 2011 at 11:40 UTC |