in reply to Re: strange map behavior
in thread strange map behavior

I tried to build a new hash out of an array with hashes, something like:
#! /usr/bin/perl -l use strict; use warnings ; my @arr = ( {'a' => 'x', 'b' => 'y', 'c' => 'z'}, {'a' => 'x1', 'b' => 'y1', 'c' => 'z1'} ) ; my %h = map {;"$_->{'a'}_$_->{'c'}" => $_->{'b'} } @arr ; print "$_ -- $h{$_}" foreach ( keys %h ) ;
Thnx
LuCa

Replies are listed 'Best First'.
Re^3: strange map behavior
by ikegami (Patriarch) on Feb 25, 2008 at 19:33 UTC
    That makes more sense. But you might want to use join to increase readability.
    my %h = map { join('_', $_->{'a'}, $_->{'c'}) => $_->{'b'} } @arr ;