Thread subroutine aufruf von formular (9 answers)
Opened by Gast at 2006-01-16 10:36

Strat
 2006-01-16 16:08
#29601 #29601
User since
2003-08-04
5246 Artikel
ModeratorIn
[Homepage] [default_avatar]
wenn da recht viele aktionen kommen (vielleicht auch noch in zusammenhang mit einem templating system), verwende ich gerne einen hash zur steuerung, z.B.
Code: (dl )
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
use CGI;
use vars qw(%Actions);
%Actions = (
eins => { code => \&Action1, template => 'action1.tmpl', x => 20 },
zwei => { code => \&Action2, template => 'action2.tmpl', a => 30 },
drei => { code => \&Action3, template => 'action3.tmpl', foo => 'bar' },
default => { code => \&Start, template => 'start.tmpl' },
};

my $cgi = CGI->new();
my $action = $cgi->param('action');

if ( defined $action and exists %Actions{$action} ) {
$Actions{$action}->{code}->($cgi, $action);
}
else {
$Actions{"default"}->{code}->($cgi, "default");
} #else
# --------------------------------
sub Action1 {
my ($cgi, $action) = @_;
my $template = $Actions{$action}->{template};
...
} # Action1
# -------------------------

Es gibt zwar einige CPAN-Module, die sowas aehnliches machen, aber da kann man (zumindest bei den mir bekannten) im Hash nicht so viele Infos unterbringen...\n\n

<!--EDIT|Strat|1137420544-->
perl -le "s::*erlco'unaty.'.dk':e,y;*kn:ai;penmic;;print"
http://www.fabiani.net/

View full thread subroutine aufruf von formular