in reply to Re: extracting elements by key from an array of hashes
in thread extracting elements by key from an array of hashes
Hello Discipulus,
grep defined, map {$_->{'k2'}} @aoh;
This works well as long as the hash value is itself defined. But if the hash entry exists with a value of undef:
my @aoh = ( { k0 => 'v0' }, { k1 => 'v1' }, { k2 => undef }, { k3 => 'v3' }, );
then the result of the grep will be indistinguishable from the case in which the hash entry does not exist at all. The following does distinguish between these two cases:
map { exists $_->{k2} ? $_->{k2} : () } @aoh;
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: extracting elements by key from an array of hashes
by mr_ron (Deacon) on Sep 26, 2015 at 00:52 UTC | |
|
Re^3: extracting elements by key from an array of hashes
by Discipulus (Canon) on Sep 25, 2015 at 19:24 UTC |