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
just like I can domygrep($_ % 2 == 0, 0..10)
grep($_ % 2 == 0, 0..10)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: make subroutine that takes expression as implicit block as first arg
by LanX (Saint) on Aug 13, 2010 at 19:56 UTC | |
Re: make subroutine that takes expression as implicit block as first arg
by kennethk (Abbot) on Aug 13, 2010 at 19:46 UTC | |
by oko1 (Deacon) on Aug 13, 2010 at 19:54 UTC | |
by kennethk (Abbot) on Aug 13, 2010 at 20:01 UTC | |
Re: make subroutine that takes expression as implicit block as first arg
by JavaFan (Canon) on Aug 14, 2010 at 10:19 UTC | |
by LanX (Saint) on Aug 14, 2010 at 16:44 UTC |
Back to
Seekers of Perl Wisdom