in reply to Re^5: Perl can do it, take 1 (sentence generation)
in thread Perl can do it, take 1 (sentence generation)
I'm not really recommending it as a good idea, just pointing out that it can be done and is pretty much the direct translation of cond. That said, the problem with doing other stuff in the blocks only arises when you leave the realms functional programming and start using side-effects (and in fact mixing side effect with returning values).
I just tried something interesting:
my ($x, $y) = (0,0); for my $i (1..2) { do { if ($i == 1) { $x; } else { $y; } } = 7; print "i = $i, x = $x, y = $y\n"; }
This doesn't work but it would have worked with an lvalue sub so why not allow lvalue do blocks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Perl can do it, take 1 (sentence generation)
by BrowserUk (Patriarch) on Jun 21, 2005 at 17:21 UTC | |
by fergal (Chaplain) on Jun 21, 2005 at 17:59 UTC |