CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: DBI:
conditional printing



Jun 20, 2009, 1:19 PM

Post #1 of 4 (5555 views)
conditional printing Can't Post

There is probably a simple solution to this, but I can't find it. I have a loop that goes through about 70 tables; for each table an sql query is created. The query returns one column (the name of a backup table, if it exists). I want to print only the results that contain a table name - not the blank lines.<p> Here is the code:$response = $sth->fetchrow_array(); print "Table = $response\n";<p> I've tried: if ($response != "" ) { print "Table = $reponse\n"; }<p> and: if ($response =~ /^$/) { print "Table = $respone\n"; }<p> Neither of these gives me the results I want; they either print everything, or print nothing at all. What is the correct syntax to only print $response if it contains a value?<p> tia

Veteran / Moderator

Jun 20, 2009, 2:00 PM

Post #2 of 4 (5554 views)
Re: [stonemonolith] conditional printing [In reply to] Can't Post

Please post a copy/paste of your code wrapped in the code tags and also post sample data retrieved that shows what you want and don't want printed.

(This post was edited by FishMonger on Jun 20, 2009, 2:01 PM)


Jun 20, 2009, 5:29 PM

Post #3 of 4 (5546 views)
Re: [FishMonger] conditional printing [In reply to] Can't Post

Here is the code, and some sample output. I want to only print the lines that contain table1_bak and table2_bak, and ignore the blank lines

$sql = "select rtrim(substring(,1,40))
from sysobjects o, sysusers u
where o.type = 'U' and o.uid = u.uid and = 'dbo'
and like '${tbl}_%'";
$sth = $dbh->prepare($sql);

($response) = $sth->fetchrow_array();
print "Table = $response\n";

****************** output ****************
Table =
Table =
Table = table1_bak
Table =
Table = table2_bak


Jun 20, 2009, 7:37 PM

Post #4 of 4 (5541 views)
Re: [stonemonolith] conditional printing [In reply to] Can't Post

I did a little more trial and error coding - I finally figured it out. I used the code print "Table = $response\n" if defined($response);


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives