Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Use of uninitialized value in string eq at ./xml_simple line 154.

Reply
Thread Tools

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

 
 
Brett.R.Davis@gmail.com
Guest
Posts: n/a
 
      08-21-2006
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;

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      08-22-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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

 
Reply With Quote
 
 
 
 
Matt Garrish
Guest
Posts: n/a
 
      08-22-2006

(E-Mail Removed) 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

 
Reply With Quote
 
Brett.R.Davis@gmail.com
Guest
Posts: n/a
 
      08-22-2006
thanks - I wouldn't have put this on the board had i not tried that....


Matt Garrish wrote:
> (E-Mail Removed) 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


 
Reply With Quote
 
Brett.R.Davis@gmail.com
Guest
Posts: n/a
 
      08-22-2006
Thanks - the information is helpful
Paul Lalli wrote:
> (E-Mail Removed) 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


 
Reply With Quote
 
Brett.R.Davis@gmail.com
Guest
Posts: n/a
 
      08-22-2006
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.
(E-Mail Removed) wrote:
> thanks - I wouldn't have put this on the board had i not tried that....
>
>
> Matt Garrish wrote:
> > (E-Mail Removed) 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


 
Reply With Quote
 
Matt Garrish
Guest
Posts: n/a
 
      08-22-2006

(E-Mail Removed) wrote:

[please don't top post]

> (E-Mail Removed) wrote:
> > Matt Garrish wrote:
> > > (E-Mail Removed) 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

 
Reply With Quote
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      08-22-2006
Matt Garrish <(E-Mail Removed)> wrote in comp.lang.perl.misc:
>
> (E-Mail Removed) wrote:
>
> [please don't top post]
>
> > (E-Mail Removed) wrote:
> > > Matt Garrish wrote:
> > > > (E-Mail Removed) 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
 
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
18 Use of uninitialized value at /opt/perl-5.005/lib/site_perl/5.005/sun4-solaris/Sybase/DBlib.pm line 450. ramanmu Perl Misc 1 05-16-2005 10:52 PM
XML::Generator::DBI - use of uninitialized value on line 180 and 187 Radhika Perl Misc 0 09-13-2004 02:00 AM
Re: Use of uninitialized value in concatenation (.) or string Error Sukhbir Dhillon Perl 1 04-05-2004 02:31 AM
Use of uninitialized value in concatenation (.) or string S Perl Misc 3 02-03-2004 09:54 PM
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