http://www.perlmonks.org?node_id=1020045


in reply to Is there a simple syntax to logically slice a hash?

define your own hgrep!
$a=key $b=value
DB<142> sub hgrep (&%) { my $f=shift; my @res; local ($a,$b); while ( ($a,$b)= splice(@_,0,2) ) { push @res, $a => $b if $f->() } return @res } DB<143> %h = ( cat=>0, cut=>1, caty=>2 ) => ("cat", 0, "cut", 1, "caty", 2) DB<144> hgrep { $a =~ /^cat/ } %h => ("cat", 0, "caty", 2) DB<145> hgrep { $b>1 } %h => ("caty", 2)

Cheers Rolf

UPDATE: see Hash::MostUtils for a similar approach.