in reply to Re^2: Concise foreach expression
in thread Concise foreach expression
I was talking about chaining maps or fors to simulate nested foreach loops.
I.o.w. list comprehensions are very hard to implement in Perl without nested blocks.
e.g. try to implement this Python example for "Pythagorean triples" w/o nesting
>>> [(x,y,z) for x in range(1,30) for y in range(x,30) for z in range( +y,30) if x**2 + y**2 == z**2] [(3, 4, 5), (5, 12, 13), (6, 8, 10), (7, 24, 25), (8, 15, 17), (9, 12, + 15), (10, 24, 26), (12, 16, 20), (15, 20, 25), (20, 21, 29)]
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Concise foreach expression
by AppleFritter (Vicar) on Aug 29, 2014 at 17:21 UTC | |
by LanX (Saint) on Aug 29, 2014 at 17:42 UTC |