Connecting and disconnecting to the same database in the same script is silly ... you could go to the trouble of creating a Singleton, or you could simply connect to the database at the beginning and use $dbh as a global variable (some globals are good). Also, you can cut back on having to worry about database errors if you turn on RaiseError:
my $dbh = DBI->connect($dsn,$user,$pass,{RaiseError=>1});
Now DBI will die with $DBI::errstr for you.

Onward ... so, what you want is to select the rows whose fields ALL do not contain the token 'NA'. You can do this with SQL, if you don't mind a lot of appended comparisons:

SELECT MID,Mname FROM ML_Lists WHERE MID != 'NA' OR ML_Lists != 'NA'
There, no Perl code needed. But, since you asked ... here is one way to do it:
my @list; my $sth = $dbh->selectall_arrayref('select MID,Mname from ML_Lists'); for (@$sth) { push @list,$_ if grep(/^NA$/,@$_) != @$_; }
grep is used to find the number of fields that contain only the string 'NA' and that number is compared to the total number of rows (@$_ in this context) to see if they are the same. If they are not, then the row contains at least one field that does not have the value 'NA', and that row is pushed to @list. (Personally, i'd rather let the database handle this job, not Perl.)

Hope this helps, and if you haven't already, then please check out The fine art of database programming. Purchasing Programming the Perl DBI isn't a bad idea either (considering you read it, of course). Hope this helps. :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: CGI Table Column Selection by jeffa
in thread CGI Table Column Selection by devslashneil

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.