Why shouldn't you? Perl idiom says that:
(.5<rand) or die "horribly";
is acceptable. In fact even encouraged. Can you explain to OP and others why your very compact and easily read example is so much worse than:

It is worse in that short circuiting or used in contexts like the one you're referring to makes for very clear syntax imitating its use in natural languages. Indeed the practical rule of a thumb is to use low-precedence logical operators for flow control and high-precedence ones to operate on values. Of course there are reasonable situations in which it is reasonable to violate this "rule", but in most cases it does apply.

if (.5<rand) { print "Wow\n"; } else { die "horribly"; }

To be fair I happen rarely enough to (have to) use a full if ... then ... else construct like the above. In this case, for example

die "horribly" if .5 < rand; print "Wow\n";
would suffice. Of course this is specific of the particular example under examination, but I make a frequent use of blocks (sometimes also for loops having the sole purpose of aliasing to $_) and of last, next, and more rarely redo and they make for quite as compact but still perfectly readable syntax.


In reply to Re^3: Ternary if versus normal if question by blazar
in thread Ternary if versus normal if question by tphyahoo

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.