![]() |
Use of uninitialized value in string eq at ./xml_simple line 154.
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; |
Re: Use of uninitialized value in string eq at ./xml_simple line 154.
Brett.R.Davis@gmail.com 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 |
Re: Use of uninitialized value in string eq at ./xml_simple line 154.
Brett.R.Davis@gmail.com 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 |
Re: Use of uninitialized value in string eq at ./xml_simple line 154.
thanks - I wouldn't have put this on the board had i not tried that....
Matt Garrish wrote: > Brett.R.Davis@gmail.com 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 |
Re: Use of uninitialized value in string eq at ./xml_simple line 154.
Thanks - the information is helpful
Paul Lalli wrote: > Brett.R.Davis@gmail.com 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 |
Re: Use of uninitialized value in string eq at ./xml_simple line 154.
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. Brett.R.Davis@gmail.com wrote: > thanks - I wouldn't have put this on the board had i not tried that.... > > > Matt Garrish wrote: > > Brett.R.Davis@gmail.com 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 |
Re: Use of uninitialized value in string eq at ./xml_simple line 154.
Brett.R.Davis@gmail.com wrote: [please don't top post] > Brett.R.Davis@gmail.com wrote: > > Matt Garrish wrote: > > > Brett.R.Davis@gmail.com 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 |
Re: Use of uninitialized value in string eq at ./xml_simple line 154.
Matt Garrish <mgarrish@gmail.com> wrote in comp.lang.perl.misc:
> > Brett.R.Davis@gmail.com wrote: > > [please don't top post] > > > Brett.R.Davis@gmail.com wrote: > > > Matt Garrish wrote: > > > > Brett.R.Davis@gmail.com 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 |
| All times are GMT. The time now is 09:33 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.