Tue, 14 Mar 2006
A Perl bug?
I have seen a strange behaviour of Perl code - the minimal code which triggers this is along the following lines:
#!/usr/bin/perl use DBIx::ShowCaller; # use DBI; my $dbh = DBIx::ShowCaller->connect('dbi:Oracle:', 'dbuser', 'dbpass') # my $dbh = DBI->connect('dbi:Oracle:', 'dbuser', 'dbpass') or die; my $temp_file = "/tmp/input.txt"; open(TEMP, $temp_file) or die "Can't open $temp_file: $!\n"; my $text = join('',<TEMP>); close TEMP; for my $radek (split (/\n/, $text)) { my $rv; ($rv) = $dbh->selectrow_array('SELECT 1 FROM DUAL'); # ($rv) = $dbh->selectrow_array('SELECT 1 FROM DUAL'); if ($rv) { print "is ok\n"; } else { print "NOT OK!\n"; } last; }
Do not even try to find out why TF it is written this way - it has been created by pruning and testing the larger script. It returns "NOT OK" from the SELECT. However, any of the following changes makes it work:
- Re-running the SELECT (i.e. uncommenting the second SELECT).
- Doing anything with
$dbh
prior to the SELECT, be it anotherprepare()
or a mere$dbh->ping
. - Replacing the
selectrow_array()
withprepare()
,execute()
, andfetchrow_array()
. - Removing the
split()
- replacing it with "my @lines=<TEMP>; for my $radek (@lines) {
". - Replacing
DBIx::ShowCaller
withDBI
(uncommenting the first two commented-out lines). - Using the
/tmp/input.txt
file with 1004 or less lines (1005+ lines make this problem appear again). This is not dependent on the file size (it can be almost all empty lines, or extremely wide lines (100+ chars per line).
Strange, ins't it? I have tested on both Linux/i386 and Linux/ia64
(with different versions of the Oracle client, altough DBI and
DBD::Oracle have the same version number on both systems). Also
selectrow_arrayref()
has the same behavour. It is Perl
5.8.6. What's going on there?