in reply to Re^4: Concise foreach expression
in thread Concise foreach expression
I once implemented a ( Monad style ;-) approach to emulate this
@results = take { [$a,$b,$c] if $a**2 +$b**2 ==$c**2 } from {1..30} $a from {1..$a} $b from {1...$b} $c
take(&$) and from(&$$) where just ordinary functions passing iterators around.
The problem I couldn't solve was a DRY scoping of the variables, to be strict I needed to surround the whole expression with
{ my($a,$b,$c); ... }
my declarations don't effect the scope of the same line. :(
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
hmm maybe this syntax is acceptable?
when called from void context from() could put the iterator into $_ , and take() could read it again from $_ if called with just one block arg...
never mind doesn't work.
|
|---|