Surely, before long, a wiser head will offer the algorithm which (may) have passed thru my brain (and out my ears) when I read your question.

But, meantime, the code below seems minimally shorter (fewer chars to type, I think) and perhaps at least as clear to a later maintainer... since the test here is not against a particular charset, but rather a test of definedness.

my @array; my ($a, $b, $c); $a = "foo"; $c = "bar"; if ($a) { # could also be written "if ( defined($a) ) {" push @array, $a; } else { $a = "NA"; push @array, $a; } if ($b) { push @array, $b; } else { $b = "NA"; push @array, $b; } if ($c) { push @array, $c; } else { $c = "NA"; push @array, $c; } print Dumper @array;

Pre-posting afterthought: it's not entirely clear whether you want an array for each row or a single, comprehensive array (or "corresponding list" as you expressed it in the narrative) so you may have to extrapolate from the code above to achieve your goal... if, indeed, you see any advantage here.

Small point: Though I myself tend to be generous with whitespace, the blank lines in your code mostly make it harder to read (here, anyway).


In reply to Re: Short version of database push for multiple variables by ww
in thread Short version of database push for multiple variables by Anonymous Monk

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.