I tend to do:
my %h2; /^cat/ and $h2{ $_ } = $h1{ $_ } for keys %h1;
Which might be seen as "cheating" as a one-liner; but it is often difficult to put the initialisation of a hash inline.
It is also quite more efficient than map and/or grep for larger hashes, by avoiding the creation of intermediate lists.
In reply to Re: Is there a simple syntax to logically slice a hash?
by BrowserUk
in thread Is there a simple syntax to logically slice a hash?
by misterperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |