Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi PerlMonks

OK...I have some code that just seems to produce errors, no matter what :) Here is the error I am getting (-w) :
Use of uninitialized value in read at conf.pl line 22. Use of uninitialized value in string eq at script.pl line 34. Use of uninitialized value in pattern match (m//) at script.pl line 52 +.

Here is the code on each of those lines:
conf.pl line 22: read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); script.pl line 34: if ((! $name{'age'}) || ($name{'age'} eq "")) { script.pl line 52: my ($query) = $ENV{'QUERY_STRING'}; if ($query =~ /^login/) { ....bla bla ... }
Anyone have any ideas why it would be producing these errors? Thanks a lot

Replies are listed 'Best First'.
Re: Warning Messages
by davorg (Chancellor) on Nov 19, 2001 at 17:20 UTC

    I'd guess it's the fact that $ENV{CONTENT_LENGTH}, $name{age} and $ENV{QUERY_STRING} are all undefined on those particular lines.

    The first and third problems are often caused by testing CGI applications in a non-CGI environment.

    Update: And looking at it again, the first also seems to be evidence of you using a home-grown (and potentially buggy) CGI parameter parser rather than the one in CGI.pm.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you don't talk about Perl club."

      Hi Dave, could you clarify what you mean by undefined on that line ? Thanks

        What he means is that if you are running this script locally on your machine, and not through a web server, the environment variables you are trying to use may not be there meaning they are undefined. Try running them through a server and see if you have the same problem.

        -----------------------------------
        Washizu
        The best offense is a good offense.

        I mean that by the time the line is executed, the variable hasn't been given a value.

        --
        <http://www.dave.org.uk>

        "The first rule of Perl club is you don't talk about Perl club."