[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] question 1 of 2 (will someone tackle this? i'm so frustrated!)



Hello everyone.
My name is andrew fiore; i'm a junior in high school at Jordan HS in Durham, NC (http://www.jordan.durham.k12.nc.us).  i'm the webmaster there... i've been learning perl by example for the last 6 months or so on UNIX, and recently i decided to try MacPerl to run scripts locally on our web server, a 150-Mhz UMAX Mac-compatible running WebSTAR.
Anyway, I'm having some problems.  Perhaps the best thing for me to do is to paste in the script i'm having trouble with. Please let me know if this is a no-no on this list; clearly, i'm brand-new.

i'm trying to write a script that allows users to leave online letters to the editor for our student paper, the Falcon's Cry (http://www.jordan.durham.k12.nc.us/fc/).  The initial letters page is letters.html. A link on that page leads to write.html, which contains the form that drives this script. It has input fields for name, email, whether you want your email address printed ($FORM{'email?'}), and the body text ($FORM{'body'}).
I'm using MacPerl 5.1.0r2.
Here's the (annotated) part of the script that is problematic:

-----------------------

$_ = $FORM{'body'};  # I use a modified version of ReadParse to grab the form data.
# 'body' refers to the body text of the letter to the editor.

$_ =~ tr|ï, Í, ñ, î, „|', ', ", ", -|; # change smart quotes and em dashes
# to dumb quotes and normal dashes.

$_ =~ s|
|<br>|g; # replaces <return>s with HTML <br>s

$datestamp = localtime (time); # get the time

$infile = "HD:Server software:WebSTAR:fc:letters.html"; # the path of the letters file

open (INPUT,"<".$infile); # read in from the letters file

$buf = <INPUT>; # put it into a variable

close (INPUT); # done with input

$outfile = "HD:Server software:WebSTAR:fc:letters.html"; # write to the same file

open (OUTPUT,">".$outfile); # Mr. Worf, open a channel

($first, $last) = split(/<!-- mark -->/, $buf); # I have an HTML tag <!-- mark -->
# in letters.html right where I want the next letter inserted;
# I want the script to split letters.html into two parts, before and after the mark.

print OUTPUT "$first"; # print the first part of the old letters.html to the file.

print OUTPUT "<hr width=\"75%\"><p>\n";

print OUTPUT "<b>Date:</b> ",$datestamp,"<br>\n"; # print the date

print OUTPUT "<b>From:</b> ",$FORM{'name'}; # print the author

if ($FORM{'email?'} eq "yes") {
print OUTPUT ",\n <a href=\"mailto:",$FORM{'email'},"\">",$FORM{'email'},"</a>\n";
} # print their email address if they want it printed

print OUTPUT "<br><br>",$_,"</p>\n";

print OUTPUT "\n<!-- mark -->\n"; # put the marker back in place, right where I
# want the next letter to go

print OUTPUT "$last"; # print the rest of the old letters.html

close (OUTPUT); # done with that print.

print "Content-type: text/html\n\n"; # return to the user

print "<html><head><title>Thank you!</title></head><body bgcolor=\"#ffffff\">
<center><img src=\"http://www.jordan.durham.k12.nc.us/fc/images/fcsmall.jpg\"
width=325 height=54 alt=\"Falcon's Cry\">
<p>Thanks for your letter. You can either take a look at the newly updated 
<a href=\"http://www.jordan.durham.k12.nc.us/fc/letters.html\">
letters page</a>, or go back to the main 
<a href=\"http://www.jordan.durham.k12.nc.us/fc/home.html\">Falcon's Cry</a> 
page.</p></center>
<a href=\"http://www.jordan.durham.k12.nc.us/fc/write.html\"><img
src=\"http://www.jordan.durham.k12.nc.us/fc/images/back.gif\" width=44 height=29
border=0 alt=\"BACK\"></a>";
# a simple HTML acknowledgement
-----------------------

So, any of you who have been kind enough to bear with me:
I begin with a letters.html file that has bascially this body (although it has some additional graphics and links above):
--------
<font size=3>
Online letters to the editor may be printed in the next issue
of the <i>Falcon's Cry</i>.<br>
<hr size=5>
<p>
Welcome to the <i>Falcon's Cry</i> Online letters section.</p>

<!-- mark -->

<div align=right><a href="write.html"><img src="images/writeus.gif" border=0
width=150 height=68></a>
</div>
<hr size=5>
<a href="home.html"><img src="images/back.gif" width=44 height=29 border=0
alt="back"></a>

</body>
</html>
--------
This script works fine the first time, although it took me hours to realize that it wouldn't work until I saved letters.html as a UNIX rather than Mac text file in BBEdit.  So I end up with something like this in the body of the file:
--------
<hr size=5>
<p>
Welcome to the <i>Falcon's Cry</i> Online letters section.</p>

<hr width="75%"><p>
Date: Mon Dec 16 15:41:06 1996<br>
From: Andrew Fiore, <a
href="mailto:beany@nando.net">beany@nando.net</a><br><br>Your mother.<br>
Is mine.<br>
af</p>

<!-- mark -->
--------
But when I run it a third time, it messes up.  Every time. I've tried different messages and stuff. I keep starting over with my original version of letters.html, and it always fails on the third letter.  It produces this in the body of letters.html:
--------
<hr size=5>
<p>
Welcome to the <i>Falcon's Cry</i> Online letters section.</p>

<hr width="75%"><p>
Date: Mon Dec 16 15:41:06 1996<br>
From: Andrew Fiore, <a
href="mailto:beany@nando.net">beany@nando.net</a><br><br>Your mother.<br>
Is mine.<br>
af</p>

<hr width="75%"><p>
<hr width="75%"><p>
<b>Date:</b> Mon Dec 16 16:01:43 1996<br>
<b>From:</b> This sucks,
 <a href="mailto:god@heaven.com">god@heaven.com</a>
<br><br>no?<br>
af</p>

<!-- mark -->
---------
So, it effectively loses the second letter completely; how that could happen I don't know. But the second letter's <hr width="75%"><p> is still there. Also, you may notice that it has lost the bottom of the file. It has inserted the third letter, inserted the <!-- mark -->, and then dropped the string $last, which contains the end of the file.

Does anyone have any ideas how to fix this?  I've fiddled for hours now, both on my personal machine and on the Jordan web server, to no avail.

Thanks so much!
andrew


                             -===-
    "...everybody is making love or else expecting rain..."
                              - bob dylan
*--------------------------------------------------------------*
| A N D R E W  F I O R E / beany@nando.net / anandroid@aol.com |
|                                                              |
|     http://www.webbuild.com/~beany/tip/                      |
|        http://users.aol.com/anandroid/poe/poe.html           |
|           http://www.duke.edu/~nbuckley/andy_and_brian.html  |
*--------------------------------------------------------------*