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, |
In reply to Re^2: extracting elements by key from an array of hashes
by Athanasius
in thread extracting elements by key from an array of hashes
by ciderpunx
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |