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

B

Brett.R.Davis

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;
 
P

Paul Lalli

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
 
M

Matt Garrish

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
 
B

Brett.R.Davis

Thanks - the information is helpful
Paul said:
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
 
B

Brett.R.Davis

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

Matt Garrish

(e-mail address removed) wrote:

[please don't top post]
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
 
A

anno4000

Matt Garrish said:
(e-mail address removed) wrote:

[please don't top post]
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
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top