#!/usr/bin/perl -w
use strict;
use HTML::Template;
use CGI qw (:standard);
use CGI::Carp qw(fatalsToBrowser);
use DB_File;
my @fields = ("title","date","author","news");
my $q = new CGI;
print $q->header;
my $template = HTML::Template->new(filename => 'news.tmpl');
my $filename="database.db";
tie(my %hash, "DB_File", $filename) or die "Can't open $filename: $!";
#add(); Temporarily not used.
my @loop_data = (); # initialize an array to hold your loop
my @keys = ();
my @values = ();
while ((my $key, my $value) = each my %hash) {
push(@keys, $key);
push(@values, $value);
}
while (@keys and @values) {
my %row_data;
$row_data{KEY} = shift @keys;
$row_data{VALUE} = shift @values;
push(@loop_data, \%row_data);
}
#delete(); Temporarily not used.
untie %hash;
$template->param(
SHOW_ALL_LOOP => \@loop_data);
print $template->output;
sub add {
my $key = time();
my $record = $key;
foreach my $field(@fields){
$record .= "\|$field";
}
$hash{$key} = "$record";
}
sub delete {
%hash = ();
}
####
News