uninitialized value's

Discussion in 'Perl Misc' started by fatted, Jan 15, 2004.

  1. fatted

    fatted Guest

    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?
     
    fatted, Jan 15, 2004
    #1
    1. Advertising

  2. fatted

    Anno Siegel Guest

    fatted <> 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
     
    Anno Siegel, Jan 15, 2004
    #2
    1. Advertising

  3. 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
     
    Gregory Toomey, Jan 15, 2004
    #3
  4. fatted

    Fatted Guest

    "Anno Siegel" <-berlin.de> wrote in message
    news:bu5s01$pn2$-Berlin.DE...
    > fatted <> 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".
     
    Fatted, Jan 15, 2004
    #4
  5. fatted

    Anno Siegel Guest

    Fatted <> wrote in comp.lang.perl.misc:
    > "Anno Siegel" <-berlin.de> wrote in message
    > news:bu5s01$pn2$-Berlin.DE...
    > > fatted <> 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
     
    Anno Siegel, Jan 15, 2004
    #5
  6. fatted

    Fatted Guest

    "Anno Siegel" <-berlin.de> wrote in message
    news:bu62ft$1jt$-Berlin.DE...
    > Fatted <> wrote in comp.lang.perl.misc:
    > > "Anno Siegel" <-berlin.de> wrote in message
    > > news:bu5s01$pn2$-Berlin.DE...
    > > > fatted <> 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.
     
    Fatted, Jan 15, 2004
    #6
  7. fatted

    Bill Guest

    "Fatted" <> wrote in message news:<bu5ve1$e1crq$-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.
     
    Bill, Jan 15, 2004
    #7
  8. fatted

    Paul Lalli Guest

    On Thu, 15 Jan 2004, Bill wrote:
    >
    > "Fatted" <> wrote in message news:<bu5ve1$e1crq$-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
     
    Paul Lalli, Jan 15, 2004
    #8
  9. fatted

    Bill Guest

    > 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?
     
    Bill, Jan 15, 2004
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. G Kannan
    Replies:
    1
    Views:
    1,260
    Eric J. Roode
    Oct 11, 2003
  2. rk
    Replies:
    1
    Views:
    6,652
    Gunnar Hjalmarsson
    Dec 7, 2003
  3. Sukhbir Dhillon
    Replies:
    1
    Views:
    6,288
    Joe Smith
    Apr 5, 2004
  4. laurent
    Replies:
    7
    Views:
    1,939
    Joe Smith
    May 27, 2004
  5. smartins68
    Replies:
    1
    Views:
    6,049
    Joe Smith
    Jun 9, 2004
Loading...

Share This Page