Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi Sandy_Bio_Perl,

I think that the problem isn't with the IS NOT NULL, but rather with the division on the column with the null value. Here's something I scratched together that works. Note the IFNULL in your SQL statement, as well as csv_null => 1 in the connection parameters:

#!/usr/bin/perl use strict; use warnings; use DBI; sub RunSqlSearch; my $spreadsheet = 'newCsv.csv'; my $query = "SELECT sid,genotype, dnabl, dnatw12 " . "FROM $spreadsheet " . "WHERE genotype = 'a' " . "AND (IFNULL(dnatw12,0)/dnabl)<0.5 " . "AND dnatw12 IS NOT NULL " ; my ($queryResult) = RunSqlSearch($query); print "Your query $query returned the following result:\n$queryResult\ +n"; sub RunSqlSearch($){ my $query = $_[0]; # error check # if ($query eq ""){die "From runSqlQuery2 - No value entered for $ +query $!\n";} # Connect to the database, (the directory containing our csv file( +s)) my $dbh = DBI->connect ("dbi:CSV:", undef, undef, { f_dir => ".", f_encoding => "utf-8", csv_eol => "\n", csv_null => 1, RaiseError => 1, }) or die $DBI::errstr; # Output using sql query # my $sth = $dbh->prepare($query); $sth->execute; my @row; my $queryResult=""; while (@row = $sth->fetchrow_array) { $queryResult .= join("\t",@row) . "\n"; } # output arguments # if ($queryResult eq ""){$queryResult = "No result found";} return ($queryResult); }

Hope that points you in the right direction.


UPDATE: Note that this will still blow up if dnabl is NULL. I played around a bit, but the IFNULL that worked in the numerator of the division failed to work in the denominator. Not sure why...

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2021-12-02 09:37 GMT
Find Nodes?
    Voting Booth?
    R or B?

    Results (18 votes). Check out past polls.