For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2007 > Use of uninitialized value in string eq









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Use of uninitialized value in string eq
Jen Spinney

2007-01-26, 6:59 pm

Hello list!

I apologize in advance for not posting a complete sample script that
shows my problem, but I can't isolate it outside of my (rather large)
perl application.

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, so I added the
following two statements right before the if statement:

print "\$exploit_name is not any sort of false\n" if $exploit_name;
print "String literal is not any sort of false\n" if 'ALL';
if ($exploit_name eq 'ALL') # <-- now line 507

I originally only check if the two strings were defined, but then I
read in perldiag that "An undefined value was used as if it were
already defined. It was interpreted as a "" or a 0, but maybe it was a
mistake. To suppress this warning assign a defined value to your
variables." So, to be safe, I verified that neither $exploit_name nor
'ALL' could be any kind of false value.

But still, this is my output:

$exploit_name is not any sort of false
String literal is not any sort of false
[*] WARNING: Use of uninitialized value in string eq at spinsploit.pl
line 507, <STDIN> line 2.

The '[*] WARNING: " bit comes from a module I'm using, which catches
SIG{__WARN__} and just prepends that string. I stepped through the
module's warning catcher with the debugger, and it was definitely sent
"Use of uninitialized value in string eq at spinsploit.pl line 507,
<STDIN> line 2." as a $_[0] value. I don't see how it could affect
the warning it was sent.

How is this possible? Any suggestions of other tests I could print
the output of or things to step through with the debugger?

- Jen
Adriano Ferreira

2007-01-26, 6:59 pm

On 1/26/07, Jen Spinney <jen.spinney@gmail.com> wrote:
> Hello list!
>
> I apologize in advance for not posting a complete sample script that
> shows my problem, but I can't isolate it outside of my (rather large)
> perl application.
>
> 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, so I added the
> following two statements right before the if statement:
>
> print "\$exploit_name is not any sort of false\n" if $exploit_name;
> print "String literal is not any sort of false\n" if 'ALL';
> if ($exploit_name eq 'ALL') # <-- now line 507


To see what you really got at $exploit_name, use Data::Dumper,
Data::Dump or any of your favourite dumpers:

use Data::Dump qw(dump);
print "\$exploit_name =", dump($exploit_name), "\n";

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

> I originally only check if the two strings were defined, but then I
> read in perldiag that "An undefined value was used as if it were
> already defined. It was interpreted as a "" or a 0, but maybe it was a
> mistake. To suppress this warning assign a defined value to your
> variables." So, to be safe, I verified that neither $exploit_name nor
> 'ALL' could be any kind of false value.
>
> But still, this is my output:
>
> $exploit_name is not any sort of false
> String literal is not any sort of false
> [*] WARNING: Use of uninitialized value in string eq at spinsploit.pl
> line 507, <STDIN> line 2.
>
> The '[*] WARNING: " bit comes from a module I'm using, which catches
> SIG{__WARN__} and just prepends that string. I stepped through the
> module's warning catcher with the debugger, and it was definitely sent
> "Use of uninitialized value in string eq at spinsploit.pl line 507,
> <STDIN> line 2." as a $_[0] value. I don't see how it could affect
> the warning it was sent.
>
> How is this possible? Any suggestions of other tests I could print
> the output of or things to step through with the debugger?
>
> - Jen
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>

Jen Spinney

2007-01-26, 6:59 pm

On 1/26/07, Adriano Ferreira <a.r.ferreira@gmail.com> wrote:
> On 1/26/07, Jen Spinney <jen.spinney@gmail.com> wrote:
>
> To see what you really got at $exploit_name, use Data::Dumper,
> Data::Dump or any of your favourite dumpers:
>
> use Data::Dump qw(dump);
> print "\$exploit_name =", dump($exploit_name), "\n";
>
> In some circumstances, the line of the warning may be wrong. So the
> problem can be around line 507 instead of exactly there.
>


$exploit_name isn't a reference, but a string scalar.

Right before the if statement, I added these lines:
print "\$exploit_name = $exploit_name\n";
print "\$exploit_name = ", Dumper($exploit_name), "\n";

This outputs:
$exploit_name = icecast_header
$exploit_name = $VAR1 = 'icecast_header'

Followed by the same warning.

Maybe it is on another line. Weird. I'll peruse around my code a bit more...

Thanks for the quick response, Adriano!
- Jen
DJ Stunks

2007-01-26, 6:59 pm

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


>
>
[color=darkred]
>
> 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

Rob Dixon

2007-01-26, 9:58 pm

Jen Spinney wrote:
>
> I apologize in advance for not posting a complete sample script that
> shows my problem, but I can't isolate it outside of my (rather large)
> perl application.
>
> 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, so I added the
> following two statements right before the if statement:
>
> print "\$exploit_name is not any sort of false\n" if $exploit_name;
> print "String literal is not any sort of false\n" if 'ALL';
> if ($exploit_name eq 'ALL') # <-- now line 507
>
> I originally only check if the two strings were defined, but then I
> read in perldiag that "An undefined value was used as if it were
> already defined. It was interpreted as a "" or a 0, but maybe it was a
> mistake. To suppress this warning assign a defined value to your
> variables." So, to be safe, I verified that neither $exploit_name nor
> 'ALL' could be any kind of false value.
>
> But still, this is my output:
>
> $exploit_name is not any sort of false
> String literal is not any sort of false
> [*] WARNING: Use of uninitialized value in string eq at spinsploit.pl
> line 507, <STDIN> line 2.
>
> The '[*] WARNING: " bit comes from a module I'm using, which catches
> SIG{__WARN__} and just prepends that string. I stepped through the
> module's warning catcher with the debugger, and it was definitely sent
> "Use of uninitialized value in string eq at spinsploit.pl line 507,
> <STDIN> line 2." as a $_[0] value. I don't see how it could affect
> the warning it was sent.
>
> How is this possible? Any suggestions of other tests I could print
> the output of or things to step through with the debugger?


You're printing output only if $exploit_name is defined. Suppose this line is
executed twice, the first time the variable is defined and the second it is not.
You will then get exactly the output you show. Write this:

die "\$exploit_name undefined" unless defined $exploit_name;
print "\$exploit_name = |$exploit_name|\n";

before your line 505 and things will be a little clearer.

HTH,

Rob


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com