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.

In reply to Re^6: Perl can do it, take 1 (sentence generation) by fergal
in thread Perl can do it, take 1 (sentence generation) by spurperl

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":