#!c:/Perl/bin/Perl.exe ## ## guestbook.cgi - a simple guestbook ## use strict; use warnings; use CGI; use CGI::Carp qw(fatalsToBrowser); use Html::Template; use Storable; # # CGI Variables # my $q = new CGI; my $name = $q->escapeHTML($q->param('name')) || ''; my $mail = $q->escapeHTML($q->param('mail')) || ''; my $text = $q->escapeHTML($q->param('text')) || ''; my $action = $q->param('action') || ''; my $template = HTML::Template->new(filename => 'guestbook.tmpl', die_o +n_bad_params => 0); my $entries = retrieve 'guestbook.dat'; # # main() # &add_new_entry() if ($action eq 'add'); &flush_entries() if ($action eq 'flush'); print $q->header(); $template->param(entries => $entries); print $template->output(); store $entries, 'guestbook.dat' or die "Can't store guestbook.dat: $!\ +n"; exit(); # # Subroutines # sub add_new_entry { $text =~ s/\n/<br \/>/g; unshift @$entries, { name => $name, mail => $mail, text => $text }; } sub flush_entries { $entries = []; }
In reply to Re: Simple Data storage
by neniro
in thread Simple Data storage
by Hissingsid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |