よく忘れるのでメモ。とりあえずperlの場合だけ書いておく。
$hash_array = [ { user_id => '01234', user_name => 'tarou', user_mail => 'tarou@example.com', user_old => 10 }, { user_id => '12121', user_name => 'hanako', user_mail => 'hanako@example.com', user_old => 15 } ];
こういうデータ構造から、user_id
とuser_name
が紐付いたハッシュリファレンスが欲しい時は
my $new_hash = +{ map { $_->{user_id} => $_->{user_name} } @$hash_array };
としてあげれば良い。