#!/usr/bin/perl
    use strict;
    use warnings;

    my @array = ({
        id      => 1,
        name    => 'Bob',
    },{
        id      => 2,
        name    => 'Anne',
    },{
        id      => 3,
        name    => 'Frank'
    });

    my %hash = map {
        $_->{id} => { name => $_->{name} }
    } @array;

    for my $id (1..3) {
        my $name = $hash{$id}->{name};
        print "User $id: $name\n";


This produces the output:
    User 1: Bob
    User 2: Anne
    User 3: Frank
Retrieved from http://hyacinth.byus.net/moniwiki/wiki.php/Perl/Array to Map
last modified 2018-03-29 11:51:07