Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Perl, Apache, Dr. Watson, and my scripts

by MrCromeDome (Deacon)
on Aug 16, 2001 at 19:31 UTC ( #105405=perlquestion: print w/replies, xml ) Need Help??

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

Hello everyone,

I am totally stumped with this one:

I have virtually identical Perl/Apache setups here at my office. On my development machine (Win2k Professional), I have ActiveState Perl and Apache 1.3.19 running, and on my web server (NT Server 4.0), I also have ActiveState Perl and Apache 1.3.19 running. When I run a certain script on my development machine, it runs ok and gives me the results that I expect. When I try to run the same script on the web server, Dr. Watson appears on the server console saying perl has performed an illegal operation, and the script then times out in the browser.

I started to do a little digging in the server error log (on the NT box), where I found the following error:

[Thu Aug 16 09:19:18 2001] [error] [client 192.168.0.28] [Thu Aug 16 0 +9:19:18 2001] d:\www\cgi-bin\view.cgi: Use of uninitialized value in +hash element at d:/Perl/lib/CGI.pm line 547.
I then went back to check the error logs on my development box, and lo-and-behold, the same error appears. I started digging into CGI.pm and discovered that this error appears in the sub parse_params, specifically on the following line:
push (@{$self->{$param}},$value);
If I'm reading this correctly, it seems like CGI is having trouble dealing with the parameters I'm giving/getting from it (which bothers me - this script has always handled them ok before this. . . ). What also bothers me is why it dies on the NT box but works fine on my desktop.

I can post the code if it will be of some help. . . it is quite lengthy however (which is why it isn't posted here). I'm not sure where to go from here. . . I already stepped it through the debugger and didn't see anything out of the ordinary (though I might not know quite what it is I'm looking for). I have warnings enabled, am using strict, and am also using CGI::Carp. Any advice is very greatly appreciated.

Thanks in advance,
MrCromeDome

Replies are listed 'Best First'.
Re: Perl, Apache, Dr. Watson, and my scripts
by azatoth (Curate) on Aug 16, 2001 at 19:39 UTC

    Off the top of my head :

    use strict on? use warnings /-w switch on? These usually help you located the "uninitialized value".

    This error basically means you have assigned a variable and are trying to pass it through a CGI.pm function. The error is being thrown at you because it's saying "Hey! $variable is empty buddy! What are you trying to pull?". When you find the variable that isn't being assigned, use some debugging methods (like a whole bunch of print "Variable is here : $variable\n" to track down the problem...

    Update : If you still have no luck, post your code here. Use code tags, and also use ReadMore tags. Check out Writeup Formatting Tips for explanations...

    Azatoth a.k.a Captain Whiplash

    Make Your Die Messages Full of Wisdom!
    Get YOUR PerlMonks Stagename here!
    Want to speak like a Londoner?
      Yeah, I have both use strict and the -w option at the top of my script, and CGI::Carp in case my script dies unexpectedly.

      I'll start throwing in some print statements. . . I don't make a lot of calls to CGI in this particular script, so hopefully it won't take long to find.

      Thanks!
      MrCromeDome

(larryk) possible bug in CGI.pm - Re: Perl, Apache, Dr. Watson, and my scripts
by larryk (Friar) on Aug 16, 2001 at 19:52 UTC
    the error message refers to $param being undefined...

    it looks like the parameter name is not defined and (in my version of CGI.pm at least) this looks like a problem...

    # from CGI.pm sub parse_params { my($self,$tosplit) = @_; my(@pairs) = split(/[&;]/,$tosplit); my($param,$value); foreach (@pairs) { ($param,$value) = split('=',$_,2); $value = '' unless defined $value; $param = unescape($param); # this is where the situation goes unchecked... # CGI::Util::unescape returns undef if $param is undef # none the wiser and no error checking! $value = unescape($value); $self->add_parameter($param); push (@{$self->{$param}},$value); } }
    so my guess is that you have a URL like:
    http://your.site.here/cgi-bin/script.pl?param1=value1&=value2&param3=v +alue3
    which is lacking "param2" and would cause the issue you are seeing. try adding...
    next unless defined $param;
    where I put the 3 line comment inside the parse_params sub

    hope this helps

    update: if this does turn out to be the problem you may want to check if the most recent version has the same problem - if so you can email the author(s) and let him/her/them know you have discovered a bug

       larryk                                          
    perl -le "s,,reverse killer,e,y,rifle,lycra,,print"
      Yeah, that will always print true ;)

      It's pretty much the situation that you describe above. . . just a little bit different. Instead of this:

      http://cygnus/cgi-bin/view.cgi?document=12345678&=name
      I have this:
      http://cygnus/cgi-bin/view.cgi?document=12345678&&tab=name
      Note the &&. If I make it a single &, it seems to work fine. Seems like I made a pretty fatal typo there. I don't know if that indicates a problem with CGI or not (my guess is not), but I do know that things work fine without the second &.

      Thanks for your help :)
      MrCromeDome

        typo - yes
        fatal - shouldn't have been (IMHO)

        CGI.pm is basically doing
        #!/usr/bin/perl -w use strict; $_ = 'test1=1&&test3=3'; for ( split '&' ) { my($param,$value) = split '='; print "param='$param'\n"; print "value='$value'\n"; # and using $param even though it is undefined the 2nd time }
        You said that both versions of apache are the same but it looks like the two versions of CGI.pm are different - you can check ~ line 22 of CGI.pm for the version number.

        if they are the same then I'm stumped - otherwise you should probably upgrade to the newer one at least as it looks like it is handling malformed URLs properly (this type anyway).

           larryk                                          
        perl -le "s,,reverse killer,e,y,rifle,lycra,,print"

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://105405]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2020-08-03 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which rocket would you take to Mars?










    Results (27 votes). Check out past polls.

    Notices?