1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| #!/usr/bin/perl
use strict; use warnings;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
my %choices = (
toto1 => \&fonc1,
toto2 => \&fonc2,
default => \&default,
);
my %redirect_to = (
google => 'http://www.google.com',
yahoo => 'http://www.yahoo.com',
);
my $cgi=new CGI;
my $choice = param("page") || "default";
if( exists $choices{$choice} ) {
$choices{$choice}->();
}
elsif( exists $redirect_to{$choice} ) {
print redirect(-uri=> $redirect_to{$choice});
}
else {
default();
}
# subroutines "choices"
sub fonc1 {
tnc('fonc1', h3( "fonc1", hr() ) );
}
sub fonc2 {
tnc('fonc2', h3( "fonc2", hr() ) );
}
sub default {
tnc('Default', p("You probably didn't intend to end up here...") );
}
# title and content of the generated html page
sub tnc {
my ($title, @content) = @_;
print header(),
start_html($title),
@content,
end_html();
}
__END__ |
Partager