Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Something is wrong and I don'tkow what

by monk2b (Pilgrim)
on Oct 18, 2000 at 03:55 UTC ( #37250=perlquestion: print w/replies, xml ) Need Help??

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

I am writing a cgi script that is full of errors that I can not find
32 print "<tr>\n"; 33 print "<td bgcolor="#8080FF">\n"; 34 print "<h3>Message For:</h3>\n"; 35 print "</td>\n"; 36 print "<td colspan="2">\n"; 37 print "<INPUT TYPE="hidden" NAME="for" VALUE="People" size="2" +>\n"; 38 print "<SELECT NAME="for\n"> 39 print "<OPTION VALUE="people">Dennis </OPTION>"; 40 print "<OPTION SELECTED VALUE="alex">alex</OPTION>
I am getting these errors:
syntax error at ./call_log line 39, near "<OPTION VALUE="people">Denni +s " Bareword found where operator expected at ./call_log line 40, near "<O +PTION SELECTED VALUE="alex">alex</OPTION" (Might be a runaway multi-line // string starting on line 39) (Missing operator before OPTION?) Bareword found where operator expected at ./call_log line 41, near "<O +PTION VALUE="andrew">andrew" (Missing operator before andrew?) Bareword found where operator expected at ./call_log line 42, near "<O +PTION VALUE="Irving">Irving</OPTION" (Might be a runaway multi-line // string starting on line 41)
Any help would be greatly appreciated Thanks Monk2b

Replies are listed 'Best First'.
Re: Something is wrong and I don'tkow what
by runrig (Abbot) on Oct 18, 2000 at 04:04 UTC
    Use q or qq. perldoc perlop.
    print q!This is a string with 'single' and "double" quotes!; my $quotes='double quotes'; print qq!This is a string with "$quotes" around a variable\n!;
    Update:Or do what extremely says below and use a here doc (I gave it a ++ since I neglected to mention it)
      This, along with the fact that line 38 and 40 are missing the ending "; (not that the " would matter because of the confusion that perl would be in due to the number of them (see runrig's post above), but the ; sure would).
Re: Something is wrong and I don'tkow what
by AgentM (Curate) on Oct 18, 2000 at 04:46 UTC
    Just thinking logically, how would you expect the Perl interpreter to differentiate between quotes you wish to be included in the string and the string boundaries? Even if that did make sense, your code fragment doesn't even remain consistent. In line 38, you finish off the HTML tag and the string. Would you expect a dumb machine like a computer to be able to guess the meaning? Often, you don't even finish off your lines with semicolons- that's the first fatal mistake you need to clean up. If you think like the interpreter (line-by-line analysis), the problem will jump out at you. But, as with everything- practice, practice, practice...

    side note- it's much cleaner to implement tables using CGI.pm.

    Keep in mind that q and ' will interpret the string literally and qq and " will interpolate any vars in that string.

    AgentM Systems nor Nasca Enterprises nor Bone::Easy is responsible for the comments made by AgentM.
Re: Something is wrong and I don'tkow what
by geektron (Curate) on Oct 18, 2000 at 04:31 UTC
    the problem is that the print strings don't have clear endings. an alternate quoting, or escaping the quotes in the HTML ( with a backslash ) will fix the problem.
Re: Something is wrong and I don'tkow what
by monk2b (Pilgrim) on Oct 18, 2000 at 10:55 UTC
    I appreciate all of the advice that was given.I was also proud of myself for getting this to work.I honestly just did not understand the advice or I would have used it.I wrote three scripts and this was the first one that I ran. I will post the other two here tommorrow after I try and run them I am sure they are better.I took everthing right out of PERL IN A NUTSHELL on the third one
    Thanks Monk2b
RE: Something is wrong and I don'tkow what
by rendhalver (Initiate) on Oct 18, 2000 at 17:49 UTC
    try using the CGI module to do your HTML output
    or escaping the " marks inside the output strings
    like so
    print "<td> bgcolor=\"#8080FF\">\n"; ugly huh !!!!
    to do this with the CGI module the above line would be
    print td(-bgcolor => "#8080FF",);
    much sexier
    ------------------------ use perl; ------------------------
Re: Something is wrong and I don'tkow what
by wardk (Deacon) on Oct 18, 2000 at 20:42 UTC

    Monk2b,

    The following snippet may not produce what you expect. Although it's no a perl issue, but an HTML form issue.

    print "<OPTION VALUE=\"people\">Dennis </OPTION>"; print "<OPTION SELECTED VALUE=\"people\">alex</OPTION>"; print "<OPTION VALUE=\"people\">andrew </OPTION>"; print "<OPTION VALUE=\"people\">Irving</OPTION>"; print "<OPTION VALUE=\"people\">Freddy</OPTION>"; print "<OPTION VALUE=\"people\">Ken</OPTION>"; print "<OPTION VALUE=\"people\">Mike</OPTION>"; print "<OPTION VALUE=\"people\">Tim</OPTION>"; print "<OPTION VALUE=\"people\">Bob</OPTION>"; print "<OPTION VALUE=\"people\">Ashley</OPTION>"; print "<OPTION VALUE=\"people\">Richard</OPTION>"; print "<OPTION VALUE=\"people\">Terrance</OPTION>"; print "<OPTION VALUE=\"people\">Ronald</OPTION>"; print "<OPTION VALUE=\"people\">Phil</OPTION>";

    I think that you are most likely desiring that the value from the popup return a value equal to the name of the string in the popup.

    Something more like this:

    print "<OPTION SELECTED VALUE=\"alex\">alex</OPTION>"; print "<OPTION VALUE=\"andrew\">andrew </OPTION>";

    Or in keeping with the above advise about escaping...

    print q!<OPTION SELECTED VALUE="alex">alex</OPTION>!;

    Otherwise all you'd ever get sent to the target (action=) CGI was "people", not the actual name.

    Good luck!

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2022-05-24 18:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (84 votes). Check out past polls.

    Notices?