[Omaha.pm] That is odd.

Jay Hannah jhannah at omnihotels.com
Thu Jul 6 06:03:03 PDT 2006


From: Sean Baker 
> This is odd.  What's with the while loop?
> 
>       my $sqlstr2 = <<EOT;
>         SELECT count(*)
>         FROM event_notify
>         WHERE prop = '$prop'
>           AND event_type = 'R'
>           AND update_type = 'M'
>           AND start_date = '$sdate'
>           AND end_date = '$sdate'
>           AND room_cat = '$room_cat'
>           AND rate_cat = '$rate_cat'
> EOT
>       my $sth2=$dbh->prepare($sqlstr2) or Vprint("Unable to 
> prepare [$sqlstr2]!! $DBI::errstr \n",1);
>       $sth2->execute() or Vprint("Unable to execute 
> [$sqlstr2]!! $DBI::errstr \n",1);
> 
>       my @row2;
>       while (@row2=$sth2->fetchrow_array) {
>         for (0.. at row2) {
>           $row2[$_] =~ s/ //g;
>         }
>         $counter = $row2[0];
>       }
> 
>       if ($counter == 0) {
>         my $sqlstr3 = <<EOT;
>         ...stuff
>       }

That IS odd. :)  That's a lot of looping when the SQL can only ever
return one row with one column in it. This part:

>       my @row2;
>       while (@row2=$sth2->fetchrow_array) {
>         for (0.. at row2) {
>           $row2[$_] =~ s/ //g;
>         }
>         $counter = $row2[0];
>       }

Should, perhaps, be written as this instead:

        my ($counter) = $sth2->fetchrow_array;
        $counter =~ s/ //g;

j


More information about the Omaha-pm mailing list