12.17.2005

HTML::Template and MySQL/DBI


#!/usr/bin/perl -w

use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use HTML::Template;
use DBI;

# database connection code

my $template;
my $newtemplate;
my $minitemplate;
my $query = new CGI;
my $sth;

$template = HTML::Template->new(
filename => "template.tmpl"
);

# this line would contain the prepare for a SELECT statement that
would return the mini-template we would be using.
$sth->execute();
$newtemplate = $sth->fetch;

$minitemplate = HTML::Template->new(
arrayref => $newtemplate
);

$minitemplate->param(test => "toost");

$template->param(content => $minitemplate->output);

print $query->header();
print $template->output;

12.16.2005

queryString.cgi


#!/usr/bin/perl -w

=head1 NAME

queryString.cgi - test script for using just the query string.
By using this method instead of the arg=param method,
it is easier to hide what we are doing.

=cut

use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);

my $query = new CGI;
my $article;

$article = $ENV{QUERY_STRING};

print $query->header;
print $article;

12.06.2005

time.cgi


#!/usr/bin/perl -w

=head1 NAME

time.cgi - basic test, for time-limit related stuff

=cut

use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);

my %TIME;
my $minDif;
my $dif;

=over

=item DESCRIPTION

Essentially, this is a test script. It uses the C function to figure out what time it is,
along with how long it's been since the user last visited. It then uses the constant, C
to figure out whether or not C minutes has passed. If it has, it tells the user that they did
whatever it was again. If it hasn't, it tells them how long until they can.

=cut

dbmopen(%TIME, "time", 0644);

use constant numberOfMinutes => 3;

print header();
my ($time) = time();

my $minRem = $TIME{$ENV{REMOTE_ADDR}} + numberOfMinutes * 60;
$minRem-=$time;
$minRem = int($minRem/60);
if ($minRem <= 0 || !defined $TIME{$ENV{REMOTE_ADDR}}) {
$TIME{$ENV{REMOTE_ADDR}} = $time;
print "It's been more than " . numberOfMinutes . " minutes. You did it again.
";
} else {
print "It's been less than " . numberOfMinutes . " minutes. You have $minRem minutes to go.
";
}

=back