This logic (corrected as per previous replies):
$col->[26] = (($col->[26] eq '0') ? '' : $col->[26] );
could also be expressed as:
$col->[26] ||= '';
If the array element in question contains "0", that will evaluate to false, and the value will be set to the empty string; the assignment will also happen if the array element is undef (which might be a good thing to handle), and if it is already an empty string (which causes an insignificant redundancy).

But if I were expecting a field to contain an 8-digit date, I'd be tempted to be at least a little more explicit about that:

$col->[26] = '' unless ( $col->[26] =~ /^\d{8}$/ );
That still allows dates like "00000000" (which would have been caught by the "||=" operator) or "99999999" (which would probably be easy to catch by using one of the Date::... modules to validate the value).

Deciding how careful you want to be is a question of trade-offs -- striking the right balance between flagrant carelessness and compulsive precision -- and how well you know your input data.


In reply to Re: ternary operator by graff
in thread ternary operator by kevind0718

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.