You could use this after the while loop: if ($sth->rows() == 0) { # First offense code }
Giff -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: 26 April, 2005 11:24 To: beginners@perl.org Subject: rows returned and while statement Ok I have an issue where I run an sql query against a database, and want to evaluate whether or not an entry occurs for a given user, if NOT then this run will be the first entry. Ok the problem occurs in the while statement, everything works as expected if the user already has an entry in the DB, however if there is NOT an entry then the while loop is skipped completely. Here is the initial code used. while(my @row = $sth->fetchrow_array) { if($row[4] == "") { $first_grace_count = $row[9]; &FirstOffense; }elsif($row[12] == "") { $second_grace_count = $row[17]; &SecondOffense; }elsif($row[20] == "") { $third_grace_count = $row[25]; &ThirdOffense; }else { print "Offender already has 3 or more offenses and should already be terminated\n"; } The sub FirstOffense gathers data and inserts it into the database as the first entry. So how can I get the FirstOffense sub to run if no rows are returned from the initial query? Chris Hood Investigator Verizon Global Security Operations Center Email: <mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED] Desk: 972.399.5900 Verizon Proprietary NOTICE - This message and any attached files may contain information that is confidential and/or subject of legal privilege intended only for the use by the intended recipient. If you are not the intended recipient or the person responsible for delivering the message to the intended recipient, be advised that you have received this message in error and that any dissemination, copying or use of this message or attachment is strictly forbidden, as is the disclosure of the information therein. If you have received this message in error please notify the sender immediately and delete the message. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>