Use of uninitialized value in string eq at ./xml_simple line 154.

Discussion in 'Perl Misc' started by Brett.R.Davis@gmail.com, Aug 22, 2006.

  1. Guest

    I can't seem to get rid of this message :

    Use of uninitialized value in string eq at ./xml_simple line 154.

    Please see code below.

    The message isn't helpful, and i have tried to understand it using
    "diagnostics, strict, and warnings".

    Thanks!

    Brett

    #initialized here
    my $device_id_found=0;
    for ($index = $cdef_row; $index <= $ib_matrix_max_rows;
    $index = $index + 1) {
    if ($device_id_found == 3) { $index =
    $ib_matrix_max_rows; }
    line 154 -> if ($device_id_found > 0) {
    if (($ib_matrix_copy[$index][0] eq "regf")) {
    if
    ($ib_matrix_copy[$index][$column_headings{'IC'}] eq "VER") {
    $device_ib_version =
    $ib_matrix_copy[$index][$part_column];
    print "INFO : IB Version Found
    $device_ib_version\n";
    $device_id_found =
    $device_id_found + 1;
    }
    elsif
    ($ib_matrix_copy[$index][$column_headings{'IC'}] eq "FAM") {
    $device_family =
    $ib_matrix_copy[$index][$part_column];
    print "INFO : Device Family Found
    : $device_family\n";
    $device_id_found =
    $device_id_found + 1;
     
    , Aug 22, 2006
    #1
    1. Advertising

  2. Paul Lalli Guest

    wrote:
    > I can't seem to get rid of this message :
    >
    > Use of uninitialized value in string eq at ./xml_simple line 154.
    >
    > Please see code below.
    >
    > The message isn't helpful, and i have tried to understand it using
    > "diagnostics, strict, and warnings".


    It's telling you that one of the two values that you are comparing with
    the eq operator on line 154 is undefined.

    > #initialized here
    > my $device_id_found=0;
    > for ($index = $cdef_row; $index <= $ib_matrix_max_rows;
    > $index = $index + 1) {
    > if ($device_id_found == 3) { $index =
    > $ib_matrix_max_rows; }
    > line 154 -> if ($device_id_found > 0) {
    > if (($ib_matrix_copy[$index][0] eq "regf")) {
    > if
    > ($ib_matrix_copy[$index][$column_headings{'IC'}] eq "VER") {
    > $device_ib_version =
    > $ib_matrix_copy[$index][$part_column];
    > print "INFO : IB Version Found
    > $device_ib_version\n";
    > $device_id_found =
    > $device_id_found + 1;
    > }
    > elsif
    > ($ib_matrix_copy[$index][$column_headings{'IC'}] eq "FAM") {
    > $device_family =
    > $ib_matrix_copy[$index][$part_column];
    > print "INFO : Device Family Found
    > : $device_family\n";
    > $device_id_found =
    > $device_id_found + 1;


    Well, which one of these lines is line 154? I count three separate eq
    comparison in this code, two of which use the same variable. So one of
    these variables is undefined:
    $ib_matrix_copy[$index][0]
    $ib_matrix_copy[$index][$column_headings{'IC'}]

    Figure out which line Perl is complaining about, and then debug until
    you figure out why that variable is undefined.

    Paul Lalli
     
    Paul Lalli, Aug 22, 2006
    #2
    1. Advertising

  3. Matt Garrish Guest

    wrote:

    > I can't seem to get rid of this message :
    >
    > Use of uninitialized value in string eq at ./xml_simple line 154.
    >
    > Please see code below.
    >
    > The message isn't helpful, and i have tried to understand it using
    > "diagnostics, strict, and warnings".
    >


    It means what it says, which is that you're attempting to compare
    values using the eq operator and one or both of the scalars is
    undefined. That it's reported at the beginning of the block means you
    have to figure out which of the comparisons inside has the undefined
    value and either give it a default value before using it, or if you
    really don't care, turn of the warnings for that block.

    Matt
     
    Matt Garrish, Aug 22, 2006
    #3
  4. Guest

    thanks - I wouldn't have put this on the board had i not tried that....


    Matt Garrish wrote:
    > wrote:
    >
    > > I can't seem to get rid of this message :
    > >
    > > Use of uninitialized value in string eq at ./xml_simple line 154.
    > >
    > > Please see code below.
    > >
    > > The message isn't helpful, and i have tried to understand it using
    > > "diagnostics, strict, and warnings".
    > >

    >
    > It means what it says, which is that you're attempting to compare
    > values using the eq operator and one or both of the scalars is
    > undefined. That it's reported at the beginning of the block means you
    > have to figure out which of the comparisons inside has the undefined
    > value and either give it a default value before using it, or if you
    > really don't care, turn of the warnings for that block.
    >
    > Matt
     
    , Aug 22, 2006
    #4
  5. Guest

    Thanks - the information is helpful
    Paul Lalli wrote:
    > wrote:
    > > I can't seem to get rid of this message :
    > >
    > > Use of uninitialized value in string eq at ./xml_simple line 154.
    > >
    > > Please see code below.
    > >
    > > The message isn't helpful, and i have tried to understand it using
    > > "diagnostics, strict, and warnings".

    >
    > It's telling you that one of the two values that you are comparing with
    > the eq operator on line 154 is undefined.
    >
    > > #initialized here
    > > my $device_id_found=0;
    > > for ($index = $cdef_row; $index <= $ib_matrix_max_rows;
    > > $index = $index + 1) {
    > > if ($device_id_found == 3) { $index =
    > > $ib_matrix_max_rows; }
    > > line 154 -> if ($device_id_found > 0) {
    > > if (($ib_matrix_copy[$index][0] eq "regf")) {
    > > if
    > > ($ib_matrix_copy[$index][$column_headings{'IC'}] eq "VER") {
    > > $device_ib_version =
    > > $ib_matrix_copy[$index][$part_column];
    > > print "INFO : IB Version Found
    > > $device_ib_version\n";
    > > $device_id_found =
    > > $device_id_found + 1;
    > > }
    > > elsif
    > > ($ib_matrix_copy[$index][$column_headings{'IC'}] eq "FAM") {
    > > $device_family =
    > > $ib_matrix_copy[$index][$part_column];
    > > print "INFO : Device Family Found
    > > : $device_family\n";
    > > $device_id_found =
    > > $device_id_found + 1;

    >
    > Well, which one of these lines is line 154? I count three separate eq
    > comparison in this code, two of which use the same variable. So one of
    > these variables is undefined:
    > $ib_matrix_copy[$index][0]
    > $ib_matrix_copy[$index][$column_headings{'IC'}]
    >
    > Figure out which line Perl is complaining about, and then debug until
    > you figure out why that variable is undefined.
    >
    > Paul Lalli
     
    , Aug 22, 2006
    #5
  6. Guest

    OK - it can be any code inside the "block"

    That makes more sense - I kept trying to narrow it down to line 154.

    I'll try and let you know.
    wrote:
    > thanks - I wouldn't have put this on the board had i not tried that....
    >
    >
    > Matt Garrish wrote:
    > > wrote:
    > >
    > > > I can't seem to get rid of this message :
    > > >
    > > > Use of uninitialized value in string eq at ./xml_simple line 154.
    > > >
    > > > Please see code below.
    > > >
    > > > The message isn't helpful, and i have tried to understand it using
    > > > "diagnostics, strict, and warnings".
    > > >

    > >
    > > It means what it says, which is that you're attempting to compare
    > > values using the eq operator and one or both of the scalars is
    > > undefined. That it's reported at the beginning of the block means you
    > > have to figure out which of the comparisons inside has the undefined
    > > value and either give it a default value before using it, or if you
    > > really don't care, turn of the warnings for that block.
    > >
    > > Matt
     
    , Aug 22, 2006
    #6
  7. Matt Garrish Guest

    wrote:

    [please don't top post]

    > wrote:
    > > Matt Garrish wrote:
    > > > wrote:
    > > >
    > > > > I can't seem to get rid of this message :
    > > > >
    > > > > Use of uninitialized value in string eq at ./xml_simple line 154.
    > > > >
    > > > It means what it says, which is that you're attempting to compare
    > > > values using the eq operator and one or both of the scalars is
    > > > undefined. That it's reported at the beginning of the block means you
    > > > have to figure out which of the comparisons inside has the undefined
    > > > value and either give it a default value before using it, or if you
    > > > really don't care, turn of the warnings for that block.
    > > >

    > > thanks - I wouldn't have put this on the board had i not tried that....
    > >

    > OK - it can be any code inside the "block"
    >
    > That makes more sense - I kept trying to narrow it down to line 154.
    >
    > I'll try and let you know.


    The quick-and-dirty approach to debugging these kinds of warnings is to
    put a print statement right before each of the comparisons. You'll
    figure out really quickly that way which value is undefined as it won't
    print either.

    Matt
     
    Matt Garrish, Aug 22, 2006
    #7
  8. -berlin.de Guest

    Matt Garrish <> wrote in comp.lang.perl.misc:
    >
    > wrote:
    >
    > [please don't top post]
    >
    > > wrote:
    > > > Matt Garrish wrote:
    > > > > wrote:
    > > > >
    > > > > > I can't seem to get rid of this message :
    > > > > >
    > > > > > Use of uninitialized value in string eq at ./xml_simple line 154.
    > > > > >
    > > > > It means what it says, which is that you're attempting to compare
    > > > > values using the eq operator and one or both of the scalars is
    > > > > undefined. That it's reported at the beginning of the block means you
    > > > > have to figure out which of the comparisons inside has the undefined
    > > > > value and either give it a default value before using it, or if you
    > > > > really don't care, turn of the warnings for that block.
    > > > >
    > > > thanks - I wouldn't have put this on the board had i not tried that....
    > > >

    > > OK - it can be any code inside the "block"
    > >
    > > That makes more sense - I kept trying to narrow it down to line 154.
    > >
    > > I'll try and let you know.

    >
    > The quick-and-dirty approach to debugging these kinds of warnings is to
    > put a print statement right before each of the comparisons. You'll
    > figure out really quickly that way which value is undefined as it won't
    > print either.


    A long while ago I wrote some code to support this technique. A sub
    detect() takes a number of scalar Perl expressions given as strings
    and generates code that checks each for definedness and prints a
    result. You eval() this code in the context of your program.
    Example:

    use Detector;

    my ( $a, $b, %c, @d);
    $b =12;
    @d = ( 0) x 10;

    eval detect qw( $a $b $c{one} $d[1]);

    This will report $a and %c{one} as undefined. Detector.pm contains


    package Detector;
    use base 'Exporter';
    our @EXPORT = qw( detect);

    sub detect {
    my @exprs = @_;
    join ";\n", map check_code( $_), @exprs;
    }

    sub check_code {
    my $expr = shift;
    "defined $expr or print q($expr undefined), qq(\\n)"
    }
    1;

    I never use it, the manual method you describe is good enough.

    Anno
     
    -berlin.de, Aug 22, 2006
    #8
    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,269
    Eric J. Roode
    Oct 11, 2003
  2. Hal Fulton

    Facebook... only 154 to go?

    Hal Fulton, Oct 11, 2005, in forum: Ruby
    Replies:
    15
    Views:
    189
    Matt Lawrence
    Oct 12, 2005
  3. Ruby Quiz

    [QUIZ] Making Change (#154)

    Ruby Quiz, Jan 25, 2008, in forum: Ruby
    Replies:
    102
    Views:
    927
    Amey Dhoke
    Jan 31, 2008
  4. Ian Evans

    Rubyquiz: Making Change (#154)

    Ian Evans, Jan 30, 2008, in forum: Ruby
    Replies:
    0
    Views:
    114
    Ian Evans
    Jan 30, 2008
  5. Radhika
    Replies:
    0
    Views:
    252
    Radhika
    Sep 13, 2004
Loading...

Share This Page