The nearest I could get is the nested ternaries.

I'd never done this before today but you can use do to achieve the Haskell effect. The do block evaluates to the last expression evaluated.

for my $i (1..2) { my $v = do { if ($i == 1) { "one"; } else { "not one"; } }; print "i = $i, v = $v\n"; }

So which is more reabable?

$v = do {if ($i == 1) { "one" } else { "not one" }; $v = $i == 1 ? "one" : "not one";

The worry I have about the Haskell way is that it's very easy to accidentally evaluate something else after the if and muck it all up (of this doesn't apply to actual Haskell, just Perl)


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

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