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

[MacPerl] CGI help



Hi everyone:

I have a problem at hand and I need your help to solve it.  I have
appended below a CGI programme for guestbook.  I am unable
to understand how to go about correcting the errors. Can anyone
out there help??

thanks


#!/usr/bin/perl -w

use 5.004;
use strict;
use CGI qw (:standard);
use Fcntl qw (:flock);

sub bail {
  my $error = "@_";
  print h1 ("Unexpected Error!"), p($error), end_html;
  die $error;
}

my (
 $CHATNAME,
 $MAXSAVE,
 $TITLE,
 $cur,
 $entries,
 $entry,
);

$TITLE = "Simple Guestbook";
print $CHATNAME = "/usr/tmp/chatfile";
$MAXSAVE = 50;

print header; start_html ($TITLE); h1 ($TITLE);

$cur = CGI->new();
if ($cur->param ("message")) {
$cur->param ("date", scalar localtime);
@entries = ($cur);
}

open (CHANDLE, "+< $CHATNAME") || bail ("cannot open $CHATNAME: $!");
flock (CHANDLE, LOCK_EX) || bail ("cannot flock $CHATNAME: $!");
while (!eof (CHANDLE) && @entries < $MAXSAVE){
$entry= CGI->new (\*CHANDLE);
push @entries, $entry;
}

seek(CHANDLE,0,0) || bail ("cannot rewind $CHATNAME: $!");
foreach $entry (@entries){
$entry->save (\*CHANDLE);
}
truncate (CHANDLE, tell (CHANDLE)) || bail ("cannot truncate $CHATNAME:
$!");
close (CHANDLE) || bail ("cannot close $CHATNAME: $!");


print hr; start_form;
print p ("Name:", $cur->textfield (
-NAME => "name:"));
print p ("Message:", $cur->textfield (
-NAME => "message",
-OVERRIDE => 1,
-SIZE => 50));
print p (submit ("send"), reset ("clear"));
print end_form; hr;

print h2 ("Prior Messages");
foreach $entry (@entries) {
printf ("%s [%s]:%s",
$entry->param ("date"),
$entry->param ("name"),
$entry->param("message");
print br();
print end_html;
}

When I syntax checked the programme, it showed the following errors:
# Global symbol "entries" requires explicit package name.
File 'Hard Disk:Applications:Quid Pro Quo °:cgi-bin:guestbook.cgi'; Line
32
# printf (...) interpreted as function.
File 'Hard Disk:Applications:Quid Pro Quo °:cgi-bin:guestbook.cgi'; Line
62
# syntax error, near ");"
File 'Hard Disk:Applications:Quid Pro Quo °:cgi-bin:guestbook.cgi'; Line
65
# Hard Disk:Applications:Quid Pro Quo °:cgi-bin:guestbook.cgi had
compilation errors.





***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch