in reply to Array to hash converstion

What you seem to have is an array-of-hash-refs (AKA AoH).

If each hashref contains only a single key/value pair, you can do this:

my %newhash; for my $href (@data_list){ $newhash{ $href->{key} } = $href->{value}; } ## If you want to print the new hash ... for my $k (sort keys %newhash){ print "$k => $newhash{$k}\n"; }
*Untested* Update: You could also use map:
my %newhash = map {{ $_->{key} } = >$_->{value} } @data_list;

     Potentia vobiscum ! (Si hoc legere scis nimium eruditionis habes)

Replies are listed 'Best First'.
Re^2: Array to hash converstion
by AnomalousMonk (Archbishop) on Jul 15, 2009 at 06:13 UTC
    my %newhash = map {{ $_->{key} } = >$_->{value} } @data_list;
    >perl -wMstrict -MData::Dumper -le "my @d_pairs = ( { key => 'foo', value => 'bar' }, { key => 'fee', value => 'fie' }, ); my %hash = map { $_->{key} => $_->{value} } @d_pairs; print Dumper \%hash; " $VAR1 = { 'fee' => 'fie', 'foo' => 'bar' };