CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Newbie question


New User

Jan 6, 2011, 8:58 AM

Post #1 of 2 (1172 views)
Newbie question Can't Post

Hi all.

I'm new to programming and am having a bit of trouble getting a very simple .pl script to work. It's for a message board, and is as basic as it gets, yet it keeps returning a 500 error. I checked with my host server and they sent me back something I don't understand.


Here's my script:

$buffer =~ tr/+/ /;
$buffer =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$buffer =~ s/<!--(.|\n)*-->/ /g;
$buffer =~ tr/\\|[|]|<|!|"|$|{|}|*|#|'|>|||;|%/ /;
@pairs = split(/&/,$buffer);
foreach $pair(@pairs){


open(INFO, ">>message_board.txt"); # Open for appending
print INFO "$yourname|$email|$subject|$message\n";
close (INFO);

open(INFO, "message_board.txt"); # Open db for reading and display
close (INFO);

print "Content-type:text/html\n\n"; #Follow with blank line

print "<html>\n";
print "<head><title>Message Board</title>\n";
print "<style type="text/css">\n";
print "h2\{font-family: Arial;font-style : normal ;font-size : 12pt; font-weight :bold;text-align :center\}\n";
print "td\{font-family: Arial;font-style : normal ;font-size : 10pt; font-weight :normal \}\n";
print "p\{ font-family: Arial;font-style : normal ;font-size : 10pt; font-weight :normal;text-align :left; width : 40em \}\n";
print "</style>\n";
print "</head>\n";
print "<body>\n";
print "<div align=\"center\">\n";
print "<h2>Message Board</h2>\n";
print "<table width=\"550\" cellpadding=\"5\" cellspacing=\"0\" border=\"1\">\n";

foreach $line (@array){

print "<tr><td>\n";
print "Posted by: $yourname <a href="mailto:$email">Return Message by Email</a><br>\n";
print "Subject:$subject<br>\n";
print "<br>\n";
print "Message:<br>\n";
print "<p>$message</p>\n";
print "</td></tr>\n";

print "</table>\n";
print "<br><br>\n";
print "<a href=\"./message_brd.html\">Post a New Message</a>\n";
print "</div>\n";
print "</body>\n";
print "</html>\n";



Bareword found where operator expected at ./ line 31, near ""<style type="text"
(Missing operator before text?)
String found where operator expected at ./ line 31, near "css">\n""
Bareword found where operator expected at ./ line 46, near ""Posted by: $yourname <a href="mailto"
(Missing operator before mailto?)
String found where operator expected at ./ line 46, near "$email">Return Message by Email</a><br>\n""
(Missing operator before ">Return Message by Email</a><br>\n"?)
syntax error at ./ line 31, near ""<style type="text"
syntax error at ./ line 46, near ""Posted by: $yourname <a href="mailto"
Execution of ./ aborted due to compilation errors.

This appears to be due to embedding double-quotes in a double-quoted string.

Anybody care to decode this for me and explain what I did wrong and how to fix it?

Thanks a million times over.


Jan 6, 2011, 12:35 PM

Post #2 of 2 (1166 views)
Re: [Aaargh] Newbie question [In reply to] Can't Post


The errors you are receiving are syntax errors. If you want them to appear in the browser as your script compiles, you should use the CGI::Carp module:

use CGI::Carp qw/fatalsToBrowser warningsToBrowser/; 
print "Content-type: text/html\n\n";

There are 2 key syntax errors in your code, and your host correctly pointed out that they were due to double quotes inside a double quoted string, which need to be escaped. Check lines 31 and 46 of your code, and escape (\") every internal double quote like so:

31.  	print "<style type=\"text/css\">\n"; 

46. print "Posted by: $yourname <a href=\"mailto:$email\">Return Message by Email</a><br>\n";

For reference, there is no need to use multiple print statements to print a block of HTML code. Here is how to print a block of HTML code (note you don't need to escape characters, just write HTML code as you normally would. It will end printing when it reaches the closing string (in this case HTML Code)):

print <<"HTML Code"; 
<div id="mydiv"></div>

Let us know if you still have problems.


(This post was edited by Zhris on Jan 6, 2011, 12:49 PM)


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives