#!/usr/bin/perl -w use strict; use CGI qw( :standard :html3 ); my @keys = qw( name email item ); my %labels = ( name => 'Name', email => 'Email Address', item => 'Item(s)' ); print header; print start_html('-title' => 'Raleigh Perl Mongers: August Meeting Sign Up', '-bgcolor' => 'white'); # See if we have data to store. my $store = 1; for my $key (@keys) { my $val = param($key); $val = '' unless defined $val; Delete($key); $val =~ s/\cM//g; $val =~ s/^\s+//; $val =~ s/\s+$//; param($key, $val); } for (@keys) { $store = 0, last if param($_) =~ /^\s*$/; } # If so, store it. if ($store) { if (-s '/export/home/raleigh/august-signup.txt' > 100_000) { print p(qq^We've been spammed... Please tell John, ASAP.^); exit 0; } if (!open FH, '+Couldn't modify signup file: $!

\n"; } else { flock FH, 2; seek FH, 0, 0; my $keep = 1; LOOP: while () { chomp; my %rec; @rec{@keys} = split /\t+/; $keep = 0; for (@keys) { if (param($_) ne $rec{$_}) { $keep = 1; last LOOP; } } } if ($keep) { seek FH, 0, 2; print FH join("\t", map { param($_) } @keys), "\n"; print h2('Thanks for your submission!'); } else { print h2('Duplicate entry...'); } close FH; } } # Otherwise, emit a prompt of sorts. else { print <

Sign-Up for the August Meeting

The idea for August's meeting is to sit around and chit-chat, while consuming soft drinks and munchies.

Please put your name, email address and a brief description of the item or items you'll be bringing, below, then hit "Submit". An attempt is made to make your address a bit harder for spammers to steal, should that be a concern (see the current list, below, for details).

Thanks!

EOF print '

', startform; for (@keys) { print Tr([td([$labels{$_}, textfield('-name' => $_, '-size' => 40)])]); } print '
', submit('-name' => 'Submit'), endform; } # Show what's in the sign-up sheet so far. if (open INP, '/export/home/raleigh/august-signup.txt') { print p('


The list so far...'); print qq^
\n^; print qq^\n^; while () { my %rec; @rec{@keys} = split /\t+/; $rec{email} =~ s/\./ dot /g; $rec{email} =~ s/\@/ at /g; print Tr([td([@rec{@keys}])]); } close INP; print "
NameEmail AddressItem(s)
\n"; } print end_html;