Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Yet Another Unitialized Value Question

by doorslam (Beadle)
on Sep 22, 2003 at 18:09 UTC ( #293212=perlquestion: print w/replies, xml ) Need Help??

doorslam has asked for the wisdom of the Perl Monks concerning the following question:

Allright, this is driving me nuts. Going through a loop updating or inserting data into an Oracle table based on a flat file and I keep getting: Use of uninitialized value in numeric eq (==) at line 435, <INF> line ######. Simplified code:
my $lock = 0; $GetDataFromTable->execute($indexnumber) || die "Can't execute GetDataFromTable ($DBI::errstr)"; unless (($lock,$updon) = $GetDataFromTable->fetchrow()) { $InsertData->execute($data1,$someotherdata,1,1,0) || die "Can't execute InsertData ($DBI::errstr)"; goto DONE; }
I evaluate some other unrelated data here, and here's the infamous line 435 that generates the warning.
if ($lock) { # Do some other stuffDon't mess with it, it's LOCKED! } elsif(...) { ... } else (...) { ... } DONE: #Do some stuff
It seems to me, the only way $lock could be uninitialized is for the fetchrow to have set it to undefined for not finding data in the table, in which case data is inserted and the line that generates the warning is skipped over. I've tried
if ($lock and 1) {
but it still generates the warning. The code works as I intend it to for all intents and purposes, but it spits out a lot of warnings, and I hate the idea of just shutting off the warning and ignoring it. Any ideas, and thanks. Blake Sorensen

Replies are listed 'Best First'.
Re: Yet Another Unitialized Value Question
by Zaxo (Archbishop) on Sep 22, 2003 at 18:25 UTC

    You have a logic error.

    To get to line 435, the object of unless must be true, i.e. ($lock, $updon) != (). $lock is therefore redefined everywhere between the unless block and the DONE: label. It may well be undef, if the database column contains nulls.

    Update, corrected some confusion of mine.

    After Compline,

      The column is a boolean flag with a not null constraint. I assume if fetchrow returns no rows, lock is undefined, but then I don't reference it again.

      If there is a row, then lock must be 0 or 1.
        Are you sure you have the right line?
        undef $lock; if ($lock) ...
        does not cause a warning for me (perl 5.8.0). It's not doing a numerical == comparison.

        Have you tried using the debugger?

Re: Yet Another Unitialized Value Question
by pijll (Beadle) on Sep 22, 2003 at 22:11 UTC
    The line numbers reported by perl do not always indicate the exact place of the error/warning. An error in a multi-line statement is always reported as if it was on the first line of the statement. In particular, if there is an error in an elsif condition, it is reported with the line number of the corresponding if.

    Your if ($lock) should not generate the warning you got, so take a good look at your elsif.

      Ah, I wondered about that. I thought it might be reporting that line number due to an error inside the if block, did not realize it would report the elsif statements back as that line number. I'll take a look at that.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://293212]
Approved by herveus
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2022-05-20 21:14 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (76 votes). Check out past polls.