Re: Use of uninitialized value in string eq



On Jan 26, 11:37 am, a.r.ferre...@xxxxxxxxx (Adriano Ferreira) wrote:
On 1/26/07, Jen Spinney <jen.spin...@xxxxxxxxx> wrote:

My problem is that I'm hit with a barrage of warnings that tell me I'm
using uninitialized values. The first warning that occurs complains
of a "use of uninitialized value in string eq" at line 505 of my
script. Line 505 (I've triple-checked the line number and the correct
source) reads:

if ($exploit_name eq 'ALL') # <-- line 505

I had no idea how $exploit_name could be undefined


In some circumstances, the line of the warning may be wrong. So the
problem can be around line 507 instead of exactly there.

This is true. The warning is thrown against the first line of the if.
If you have elsifs which trigger the warning, the line will be 505. I
probably didn't explain that very well so please have a look at this
example:

C:\tmp>cat -n tmp3.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 my $undefined;
7 my $defined = 'something';
8
9 if ( $defined eq 'defined' ) {
10 print "\$defined was defined\n";
11 }
12 elsif ( $undefined eq 'defined' ) {
13 print "\$undefined was defined\n";
14 }
15
16 __END__

C:\tmp>tmp3.pl
Use of uninitialized value in string eq at C:\tmp\tmp3.pl line 9

The warning actually occurs on line 12, but it's thrown against 9
because that's where the if block starts.

HTH,
-jp

.



Relevant Pages

  • Re: Function Warning - Null Reference
    ... Warning 1 Function 'Dec2hms' doesn't return a value on all code paths. ... These include String, Integer, DateTime and Boolean ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Function Warning - Null Reference
    ... Warning 1 Function 'Dec2hms' doesn't return a value on all code paths. ... null reference exception could occur at run time when the result is used. ... default value for a String is String.Empty, the default value for an Integer ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Visual Studio 2005 - Warning in the Error List Window
    ... I'm receiving the same warning, and although this has been brought up ... Public sBillingAddress1 As String ... Private Sub LoadAddress() ... Dim Address As New addressEntry ...
    (microsoft.public.dotnet.languages.vb)
  • Re: PROBLEM
    ... tmp.c:1: warning: initialization discards qualifiers from pointer ... The problem with C compilers is that these options are not enabled ... Compiling new C code in a mode that flags possible writes to string ... become illegal if the language were modified to make string literals ...
    (comp.std.c)
  • Re: SetFocus convert from 2003 to 2005 problem
    ... vs2005 has this feature builtin. ... Private Sub SetFocus ... Warning 2 'Public Overridable Sub RegisterStartupScript(key As String, ...
    (microsoft.public.dotnet.framework.aspnet)