could also be expressed as:$col->[26] = (($col->[26] eq '0') ? '' : $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).$col->[26] ||= '';
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:
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).$col->[26] = '' unless ( $col->[26] =~ /^\d{8}$/ );
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |