Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Uninitialised value in string error(was: Debug pukes here.)

by Anonymous Monk
on May 17, 2002 at 00:05 UTC ( [id://167146]=perlquestion: print w/replies, xml ) Need Help??

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

if ($q->param('field') eq "") {&printform()} else {&results()}

"...but this is exactly how the line is typed in the book!" I'll let the book remain nameless but it really is what is in the book. I get the message, "Use of unitialized value in string eq at select.cgi line 18.

Any one who helps can have a slice of the best rhubard crisp you ever tasted. Unfortunately, I'll have to eat it in your honor... TIA!

Edit kudra, 2002-05-17 Changed title; added code tags

Replies are listed 'Best First'.
Re: Debug pukes here.
by Zaxo (Archbishop) on May 17, 2002 at 01:07 UTC

    &CGI::param is a method sub, parens are correct. The uninitialized value message means that either $q doesnt exist or there is no field called 'field' in the cgi data. Browsers generally don't return empty fields in POST, so not defined $q->param('field') might be an advisable as an additional test.

    After Compline,
    Zaxo

Re: Debug pukes here.
by myocom (Deacon) on May 17, 2002 at 00:23 UTC
    This could be any number of things, but basically it means that the first part of your if condition is uninitialized. This could be because the $q object wasn't created, for example, or it could be that you have parentheses where you should have curly braces. Try this instead:
    if ($q->param{'field'} eq "") { # Note that 'field' has curlies now &printform() } else { &results() }
    While I'm at it, I'm betting that the & isn't really needed (and may have unwanted side effects) here. See A question of style for more information.
    "One word of warning: if you meet a bunch of Perl programmers on the bus or something, don't look them in the eye. They've been known to try to convert the young into Perl monks." - Frank Willison
Re: Debug pukes here.
by DigitalKitty (Parson) on May 17, 2002 at 04:04 UTC
    Hi.

    O.K. I think I see the problem. Can you check for these:
    In your HTML form, have you set up the form fields similar to this:
    <FORM METHOD=POST ACTION="/Path/To/CGI/app.pl ( or .cgi )> Name: <INPUT TYPE=TEXT NAME="name"> <BR> <INPUT TYPE=SUBMIT VALUE="Click here to send the data!"> </FORM>


    Then...in the program that is called by action ( see above ), it should look something like this:

    #!/usr/bin/perl -wT use strict; use CGI qw( :standard ); use CGI::Carp qw( fatalsToBrowser ); print "Content-type: text/html\n\n"; my $name = param( "name" ); #This might be the problem. if( $name eq "" ) { &printform(); } else { &results(); } ...the remainder of your code...

    /msg me if this doesn't solve the problem o.k?
    Hope this helps,
    -DK ( "Meow")
      Hola, DK. I didn't understand the change of the word 'field' to "name" so my brain could not successfully interpret a parse of your reply. I am not calling this program from an HTML document that creates a form via a call to a cgi or pl script. I'm actually just running the script directly. And, it was discovered that I could not execute the script with the browser because of simple perms setting (chmod 755 fixed it). While I could execute it as user and root at the O/S, and the owner was nobody, the browser could not execute (possibly because the user is in the set "other"?, not UID or GID.). Anyhow, the issue is resolved. Thanks for being kind enough to reply, DK! Andrew L.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-18 20:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found