in reply to Returning value or key from a hash
use strict; use warnings; my %hash = ( foo => 'bar', 42 => 23, hello => 'world', ); my @interesting_keys = qw(foo hello); my @values = map { $hash{$_} } @interesting_keys; my @interesting_values = qw(bar 23); my %reversed_hash = reverse %hash; my @keys = map { $reversed_hash{$_} } @interesting_values;
Update: Made the code conform to strict, after tirwhan's note.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Returning value or key from a hash
by tirwhan (Abbot) on Apr 07, 2006 at 12:47 UTC | |
|
Re^2: Returning value or key from a hash
by tlm (Prior) on Apr 07, 2006 at 14:18 UTC | |
by Corion (Patriarch) on Apr 07, 2006 at 16:39 UTC | |
by Gavin (Archbishop) on Apr 07, 2006 at 20:07 UTC |