Computing.Net > Forums > Programming > PERL Guestbook help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

PERL Guestbook help

Reply to Message Icon

Name: Rebecca
Date: May 12, 2003 at 12:06:13 Pacific
OS: Windows 2000
CPU/Ram: P3/1ghz. 256
Comment:

I've got an assignment that requires me to write a guestbook in Perl, but with funny requirements. Once the 2nd message is sent through it's supposed to be placed on a second fine, the third one on another one and so on ... In addition, the user should be able to click on a link 1.txt, 2.txt, etc. to be able to read each message. I've got the code to where it passes the information to the cgi script and writes it to 1 file. However, I can't seem to figure out how to write the cgi so that each message following is written to a new file.

The last thing I'm having trouble with is we're supposed to have certain requirements on different lines. How do I write in the cgi script to go to the next line in the text file? This is what I have so far:

my @months = qw(January February March April May June July August September October November December);

my @days = qw(Sunday Monday Tuesday Wednesday Thursday Friday);

my @time = localtime;

while ()
{
open (TEXT, ">>1.txt");
print TEXT ' ';
print TEXT $days[$time[6]];
print TEXT ", ";
print TEXT $months[$time[4]];
print TEXT " ";
print TEXT $time[3];
print TEXT ", ";
print TEXT $time[5]+1900;
print TEXT " ";
print TEXT $time[2];
print TEXT ":";
print TEXT $time[1];
print TEXT ":";
print TEXT $time[0];
print TEXT ' ';
}
my $name = param('Name');
my $comment = param('comment');
print TEXT $name;
print TEXT ' ';
print TEXT $comment;

print "Thank you, $name";

and as you can see, it doesn't take into account more than one text file muchless allow for various items to go on multiple lines.



Sponsored Link
Ads by Google

Response Number 1
Name: gpp
Date: May 12, 2003 at 12:26:19 Pacific
Reply:

It doesnt look like your code survived the posting process.. Either post it with coder or email it to me.


0

Response Number 2
Name: Nema
Date: May 12, 2003 at 12:58:08 Pacific
Reply:

#!/usr/bin/perl -w
use strict;
use CGI qw(:standard) ;
print header;
print'';

my @months = qw(January February March April May June July August September October November December);

my @days = qw(Sunday Monday Tuesday Wednesday Thursday Friday);

my @time = localtime;

while ()
{
open (TEXT, ">>1.txt");
print TEXT ' ';
print TEXT $days[$time[6]];
print TEXT ", ";
print TEXT $months[$time[4]];
print TEXT " ";
print TEXT $time[3];
print TEXT ", ";
print TEXT $time[5]+1900;
print TEXT " ";
print TEXT $time[2];
print TEXT ":";
print TEXT $time[1];
print TEXT ":";
print TEXT $time[0];
print TEXT ' ';
}
my $name = param('Name');
my $comment = param('comment');
print TEXT $name;
print TEXT ' ';
print TEXT $comment;
print "Thank you, $name";

if that still doesn't work, I posted it to
http://cs.selu.edu/~w0242718/guestbook.txt

Thanks


0

Response Number 3
Name: gpp
Date: May 12, 2003 at 13:09:15 Pacific
Reply:

I'm not really sure what you're trying to do in your script, but heres an example of how to read from and write to a file..


#! perl


$filename="MyInFile.txt";
#Open the file for reading
open(spreadFile, $filename);
#Open the file for writing, and check to make sure the file opened!
open(fileOUT, ">MyOutFile.txt") or dienice("Can't open File: $!");

while($line = <spreadFile>){  # Read file line at a time
  print fileOUT $line;
  
}

close(spreadFile);


0

Response Number 4
Name: Nema
Date: May 12, 2003 at 14:35:20 Pacific
Reply:

Yeah ...

The reading one line at a time would help except for the fact that I have to write EACH message to a new file. I can't have them all written to the same file.

as my professor put it " Design a system where each message is placed on a separate file. The message names should be 1.txt, 2.txt, etc. The message names are to start where the last number +1. Do no attempt to plan for simultaneous message in put. Assume one user at a time. The first line should be the date and time, 2nd should be user's name, 3rd line shoudl be blank, and 4th line should be their comments. When you click on the read comments, there should be a link to each message that has been put in."

I'm not sure if that helps or not ....


0

Response Number 5
Name: SN
Date: May 12, 2003 at 19:49:19 Pacific
Reply:

Here's what I did at my forum in perl on sharingds.org - you may not need the part where it makes the date the filename. What you need is the while loop that checks to see how far up the existing files go, ie 1.txt, 2.txt, 3.txt, etc. This is then appended to the filename and can be opened for writing.
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) 
=     localtime(time);
$dirpath="../discussion/";
if ($mon < 9) {$mon="0".($mon+1);}
else {$mon=$mon+1;}
if ($mday < 10) {$mday="0".$mday;}
$date=($year+1900).$mon.$mday;
$filename=$dirpath.$date;
$textdate=($mon)."-".$mday."-".($year+1900);

$i=0;

while (-e $filename."$i.txt")
{
     $i++;
}

$filename=$filename."$i.txt";
open(OUTF,">$filename") or dienice("Can't open $filename 
for creating $!");


0

Related Posts

See More



Response Number 6
Name: SN
Date: May 12, 2003 at 21:49:19 Pacific
Reply:

To go to the next line, print out a "\n" to the text file.
-SN


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: PERL Guestbook help

perl guestbook www.computing.net/answers/programming/perl-guestbook/1333.html

Need Perl Programming Help!!!!! www.computing.net/answers/programming/need-perl-programming-help/762.html

perl script help www.computing.net/answers/programming/perl-script-help/7901.html