in reply to extracting elements by key from an array of hashes
my %hash = ( k0 => 'c0', k1 => 'v1', k2 => 'v2', k3 => 'v3', ); my $search = 'k2'; my $val = $hash{$search};
Even if the keys aren't unique, you might want to store the data in a HoA instead:
my %hash = ( k0 => ['c0'], k1 => ['v1'], k2 => ['v2', 'v42'], k3 => ['v3'], ); my $search = 'k2'; my @vals = @{ $hash{$search} };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: extracting elements by key from an array of hashes
by ciderpunx (Vicar) on Sep 25, 2015 at 10:06 UTC | |
by choroba (Cardinal) on Sep 25, 2015 at 10:35 UTC | |
by davido (Cardinal) on Sep 25, 2015 at 14:57 UTC | |
by Anonymous Monk on Sep 25, 2015 at 10:45 UTC |