in reply to Array to hash converstion
If each hashref contains only a single key/value pair, you can do this:
*Untested* Update: You could also use map: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"; }
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 |