I'm rewriting a piece of C code that uses the OpenClient libraries to set
a row in a process table under certain circumstances. The chunk of Perl
code that handles this is:
package init_process;
...
my $cmd = "exec sales2..sa_initprocess ", $dbh->quote($item_src) . ",
" . $proc_id;
my $sth = $dbh->prepare("$cmd") or warn(...);
$sth->execute() or warn(...);
my $numrows = 0;
do
{
while (my @row = $sth->fetchrow_array())
{
print join("::", @row), "\n"; ### line 45
($a, $b, $c, $d, $e, $f, $g, $h, $i) = @row;
}
} while ($sth->{syb_more_results});
$sth->finish();
print "numrows: $numrows\n";
The output of this is:
Use of uninitialized value at init_process.pm line 45
Use of uninitialized value at init_process.pm line 45
/tmp/xxx.tmp::EXTtranldr::Apr 25 2001 12:26PM::::1::1::Apr 25 2001
12:00AM::0::0::0::0::0::0::0::8
0
numrows: 2
If I remove the recommended do { } while ($sth->{syb_more_results}) I get:
Use of uninitialized value at init_process.pm line 45
Use of uninitialized value at init_process.pl line 45
/tmp/xxx.tmp::EXTtranldr::Apr 25 2001 12:26PM::::1::1::Apr 25 2001
12:00AM::0::0::0::0::0::0::0::8
numrows: 1
The second set of results is closer to what I expect, however I don't
understand why Perl thinks @row is an uninit value when it properly gets
the info out of @row.
I ran this in debug mode, and the whole thing seems to execute out of
order.
$sth->finish();
print join("::", @row), "\n";
$numrows++;
($a,...$i) = @row;
while (my @row = $sth->fetchrow_array())
{
$sth->finish();
and just after the print on @row occurrs, a x @row yields:
empty array
So the questions are:
1.) Why is the recommended way of retrieving stored proc results screwing
this up?
2.) Why is @row uninitialized when I can print its values just fine
3.) Why is the order of execution under the debugger causing the finish to
be called first, etc.
Running with the do {} while() makes the order of execution under -d even
more disordered.
Thanks,
Curt