Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > uninitialized value's

Reply
Thread Tools

uninitialized value's

 
 
fatted
Guest
Posts: n/a
 
      01-15-2004
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?
 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      01-15-2004
fatted <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> 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
 
Reply With Quote
 
 
 
 
Gregory Toomey
Guest
Posts: n/a
 
      01-15-2004
fatted wrote:

> 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
 
Reply With Quote
 
Fatted
Guest
Posts: n/a
 
      01-15-2004
"Anno Siegel" <(E-Mail Removed)-berlin.de> wrote in message
news:bu5s01$pn2$(E-Mail Removed)-Berlin.DE...
> fatted <(E-Mail Removed)> wrote in comp.lang.perl.misc:
>
>>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".


 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      01-15-2004
Fatted <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> "Anno Siegel" <(E-Mail Removed)-berlin.de> wrote in message
> news:bu5s01$pn2$(E-Mail Removed)-Berlin.DE...
> > fatted <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> >
> >>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
 
Reply With Quote
 
Fatted
Guest
Posts: n/a
 
      01-15-2004
"Anno Siegel" <(E-Mail Removed)-berlin.de> wrote in message
news:bu62ft$1jt$(E-Mail Removed)-Berlin.DE...
> Fatted <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> > "Anno Siegel" <(E-Mail Removed)-berlin.de> wrote in message
> > news:bu5s01$pn2$(E-Mail Removed)-Berlin.DE...
> > > fatted <(E-Mail Removed)> wrote in comp.lang.perl.misc:


> 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.


 
Reply With Quote
 
Bill
Guest
Posts: n/a
 
      01-15-2004
"Fatted" <(E-Mail Removed)> wrote in message news:<bu5ve1$e1crq$(E-Mail Removed)-berlin.de>...

> >>
> >>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.
 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      01-15-2004
On Thu, 15 Jan 2004, Bill wrote:
>
> "Fatted" <(E-Mail Removed)> wrote in message news:<bu5ve1$e1crq$(E-Mail Removed)-berlin.de>...
>
> > >>
> > >>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

 
Reply With Quote
 
Bill
Guest
Posts: n/a
 
      01-15-2004
> 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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use of uninitialized value in concatenation smartins68 Perl 1 06-09-2004 05:46 AM
"uninitialized value in join or string" laurent Perl 7 05-27-2004 04:53 AM
Re: Use of uninitialized value in concatenation (.) or string Error Sukhbir Dhillon Perl 1 04-05-2004 02:31 AM
uninitialized value in pattern match rk Perl 1 12-07-2003 09:35 AM
Use of uninitialized value in concatenation (.) at register.pl line 38, <STDIN> line 10. G Kannan Perl 1 10-11-2003 11:58 AM



Advertisments