uninitialized value's

F

fatted

Below is a section of the output from perl running a script with the
-d option:

main::(cost.cgi:314): if($idle->[0] == 0 && $idle->[1] == 0)
main::(cost.cgi:315): {
DB<4> x $idle->[0]
0 0
DB<5> x $idle->[1]
0 2
DB<6> n
Use of uninitialized value in numeric eq (==) at cost.cgi line 314,
<CONFIG> line 106.

Whats going on? Which value is uninitialised?
 
A

Anno Siegel

fatted said:
Below is a section of the output from perl running a script with the
-d option:

main::(cost.cgi:314): if($idle->[0] == 0 && $idle->[1] == 0)
main::(cost.cgi:315): {
DB<4> x $idle->[0]
0 0
DB<5> x $idle->[1]
0 2
DB<6> n
Use of uninitialized value in numeric eq (==) at cost.cgi line 314,
<CONFIG> line 106.

Whats going on? Which value is uninitialised?

Use some logic.

The message told you there is an undefined value in a "==" operation.
There are two "==" operations in line 314 with a total of four operands.
Two of the operands are "0" and can't be undefined. That leaves
"$idle->[0]" and "$idle->[1]". You need a newsgroup to tell you that?

You will need other means, such as printing out the values, to find out
whether it's the first one, the second one, or both.

Anno
 
G

Gregory Toomey

fatted said:
Below is a section of the output from perl running a script with the
-d option:

main::(cost.cgi:314): if($idle->[0] == 0 && $idle->[1] == 0)
main::(cost.cgi:315): {
DB<4> x $idle->[0]
0 0
DB<5> x $idle->[1]
0 2
DB<6> n
Use of uninitialized value in numeric eq (==) at cost.cgi line 314,
<CONFIG> line 106.

Whats going on? Which value is uninitialised?

How do we know? Print them out, as a debugging device.

How do you do debugging in other situations?

gtoomey
 
F

Fatted

Anno Siegel said:
fatted said:
Below is a section of the output from perl running a script with the
-d option:

main::(cost.cgi:314): if($idle->[0] == 0 && $idle->[1] == 0)
main::(cost.cgi:315): {
DB<4> x $idle->[0]
0 0
DB<5> x $idle->[1]
0 2
DB<6> n
Use of uninitialized value in numeric eq (==) at cost.cgi line 314,
<CONFIG> line 106.

Whats going on? Which value is uninitialised?


Use some logic.

For those unfamiliar with the perl debugger :),

x expr

Evaluates its expression in list context and dumps out the result in a
pretty-printed fashion.

from my output my understanding is that the variable:

$idle->[0] has a value of 0
and
$idle->[1] has a value of 2

So logically :), I'm a bit miffed by the "uninitialized value" warning for
line 314.
You need a newsgroup to tell you that?
:)

You will need other means, such as printing out the values, to find out
whether it's the first one, the second one, or both.

I've printed out the values both before and after, and they're always
numeric, but line 314 still throws an "uninitialized value".
 
A

Anno Siegel

Fatted said:
Anno Siegel said:
fatted said:
Below is a section of the output from perl running a script with the
-d option:

main::(cost.cgi:314): if($idle->[0] == 0 && $idle->[1] == 0)
main::(cost.cgi:315): {
DB<4> x $idle->[0]
0 0
DB<5> x $idle->[1]
0 2
DB<6> n
Use of uninitialized value in numeric eq (==) at cost.cgi line 314,
<CONFIG> line 106.

Whats going on? Which value is uninitialised?


Use some logic.

For those unfamiliar with the perl debugger :),

Uh, I'm sorry. I somehow didn't see the debugger lines. I am in fact
not particularly familiar with it.

In that case, use some illogic :)

Perl's line numbers in warnings and errors aren't always exact. In
particular with multi-line statements (like the "if" above) it happens
that the error is a few lines down into the statement, but Perl reports
the first line. So the undefined value could be a few lines down. In
my experience, it is rarely (never?) in the "else" or "elsif" parts
(if present), but the "if" block is fair game.

Anno
 
F

Fatted

Perl's line numbers in warnings and errors aren't always exact. In
particular with multi-line statements (like the "if" above) it happens
that the error is a few lines down into the statement, but Perl reports
the first line. So the undefined value could be a few lines down. In
my experience, it is rarely (never?) in the "else" or "elsif" parts
(if present), but the "if" block is fair game.

Damn, damn, damn, damn. It was in an elsif.
I did the exact same thing about six months ago (I even posted a message
about why the compiler does this!), and was similarly thrown by the compiler
message, spending a bunch of time on the line mentioned and not on the one
with the error about 5 lines down.
(Mental Note: Must remember stuff)

Thanks.
 
B

Bill

Fatted said:
from my output my understanding is that the variable:

$idle->[0] has a value of 0
and
$idle->[1] has a value of 2

So logically :), I'm a bit miffed by the "uninitialized value" warning for
line 314.

The value of undef, printed as scalar, is 0. Try setting $idle->[0]
explictly to 0 in the program and see if the error persists.
 
P

Paul Lalli

Fatted said:
Whats going on? Which value is uninitialised?

from my output my understanding is that the variable:

$idle->[0] has a value of 0
and
$idle->[1] has a value of 2

So logically :), I'm a bit miffed by the "uninitialized value" warning for
line 314.

The value of undef, printed as scalar, is 0. Try setting $idle->[0]
explictly to 0 in the program and see if the error persists.


You are clearly not familiar with the perl debugger. If $foo is undef, `x
$foo` returns "0 undef", not "0 0".

Furthermore, printing undef does not give 0, it gives the empty string.
Using undef in a numeric context (which printing is not) gives 0.

Paul Lalli
 
B

Bill

I've printed out the values both before and after, and they're always
numeric, but line 314 still throws an "uninitialized value".

One other thing--sometimes the warnings for an inner block of code get
shifted to the end of the block in line position. Are there any ==
comparisonns in the lines above the one Perl claims is wrong?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top