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

Re: [MacPerl-WebCGI] compilation error



Hi incas,

probably you ment $#entries (which is the uppermost index of @entries,
in most cases the number of entries minus one) instead of $entries.
printf seamingly does not like round brackets (...).

I do not understand the script, but nevertheless it now can be compiled.

For the sake of readability you should mind the block structure
and its indentation; like this:


=====================

#!/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= "Aztec Guestbook";
$CHATNAME = "/usr/tmp/chatfile";
$MAXSAVE = 100;

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 => 100));
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;

==========================

Detlef Lindenthal <detlef@lindenthal.com>


==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org