bladx has asked for the wisdom of the Perl Monks concerning the following question:
#!/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 = (); }
<html> <head><title>News</title></head> <body bgcolor=#eeeeee> <center> <TMPL_LOOP NAME="SHOW_ALL_LOOP"> <table width=400 border=1 cellspacing=0 cellpadding=0> <tr><td valign=top bgcolor=#dddddd> <b>Key</b>:<TMPL_VAR NAME="KEY"><br> <b>Value</b>:<TMPL_VAR NAME="VALUE"><br><br> </td></tr> </table><br> </TMPL_LOOP> </center> </body> </html>
|
---|
Replies are listed 'Best First'. | |
---|---|
map can help you
by larryk (Friar) on Dec 29, 2001 at 19:55 UTC |