This all stuff used in many languages and not specific to Perl.

The ternary operator works in the form of $condition_expr ? $true_expr : $false_expr. The conditional expression (here: ($X < 10)) is evaluated first. If it tests true, the $true_expr is then evaluated and its result is returned. Likewise with $false_expr if the conditional expression evaluated to false.

Then you have a shortcut operator $foo op= $bar;, where op stands for a mathematical, bitwise, or logical operator - here +. It is a shortcut for $foo = $foo op $bar;. So $foo += $bar; is a concise way to say "increase $foo by $bar".

So a sort-of token-by-token translation of the expression in my post to English would read something like "$Y is increased by either (if $X is less than 10) 2000 or by 1900 (otherwise)".

Obviously the first time you see such a construct it'll look strange. And it certainly isn't the point to use them wherever possible. Brevity is not a goal for its own sake. But assuming familiarity with such constructs, readability is maximized by choosing the briefest possible form that follows the structure of a natural language sentence describing the same thought. In this case this is statement is closest to how I'd explain the intent: "add the century depending on the year". It expresses exactly that in a straightforward manner: there's one condition, one addition/assignment, and the numbers, without any artificial extra verbiage.

Makeshifts last the longest.


In reply to Re^3: Syntax error - beginner question by Aristotle
in thread Syntax error - beginner question by ctp

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.