http://qs1969.pair.com?node_id=854993

myuserid7 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I want to make my own subroutine work like grep() or map(), being able to take either a block or an expression as a first argument; and if an expression is given, automatically put an it in an implicit block, just like grep() and map() does The block part is easy; but is it possible to make it do the expression part? For example, how to define mygrep(), such that I can do
mygrep($_ % 2 == 0, 0..10)
just like I can do
grep($_ % 2 == 0, 0..10)