# or using a slice (might be more efficient, but doesn't read as nicel +y) sub hash_slice { my ($hr, @k) = @_; my %ret; @ret{@k} = @$hr{@k}; return %ret; }
Personally, I think this one reads very nicely, and this is most likely the approach I would go with. Nice side-effect: in case I ever need to step through with "perl -d" (e.g. to check for mangled data), this versions provides a handy place for a breakpoint where I can dump %ret before it gets returned.
In reply to Re: How to extract part of a hash
by graff
in thread How to extract part of a hash
by rhesa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |