in reply to Short version of database push for multiple variables
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).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Short version of database push for multiple variables
by tobyink (Canon) on May 13, 2012 at 19:23 UTC |