For what it's worth, some of this applies equally in many languages such as C and C++. There's not really a concept of definedness in C/C++, but the concept of short circuiting in expressions using ||, and of ternary operators is nearly identical.
But please be warned that the semantics of the || and && operators in C/C++ is significantly different to Perl. For example, this Perl code:

my $var; $var = 0; $var = $var || 30; print "1. var=$var\n"; $var = 0; $var ||= 30; print "2. var=$var\n";
prints:
1. var=30 2. var=30

While this C++ code:

int var = 0; var = var || 30; printf("1. var=%d\n", var); // var ||= 30; // oops, syntax error in C++
prints:
1. var=1
Why? Because in C/C++, the (short-circuiting) || and && operators always return 0 or 1. Unlike Perl, they do NOT return the last value evaluated.

IMHO, this deliberate Perl change in semantics of these two venerable short-circuiting operators was a clever innovation from Larry, making them more convenient to use, notably when setting default values.


In reply to Re^2: Need clean code by eyepopslikeamosquito
in thread Need clean code by ravi45722

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.