1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
my @subs;
my $ini = 'test.ini';
use Config::IniFiles;
my $cfg = Config::IniFiles->new( -file => "$ini" )
|| die "Error: Probleme beim Lesen der Ini-Datei";
foreach ($cfg->Parameters('do')) {
push (@subs, $cfg->val('do', $_ ));
}
foreach (@subs) {
$_->();
}
sub1 ...
1
2
3
4
5
6
7
8
9
my $test = "sub3";
my @subs1 = (\&sub1, \&sub2, \&$test);
push (@subs1, \&sub4);
foreach (@subs1) {
$_->();
}
1 2 3 4 5 6
my %subs = ( 'fuer_irgendwas' => sub { say 'HALLO' }, 'fuer_was_anderes' => sub { say 'WELT' }, ); $subs{'fuer_irgendwas'}->();
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
#!/usr/bin/perl use strict; use warnings; my %funktions=( default => \&do_default, sub1 => \&do_sub1, sub2 => \&do_sub2, sub3 => \&do_sub3, ); open(my $fh, '<', $file) or die( "ERROR OPEN $file ($!)\n" ); while(my $cmd=<$fh>) { chomp($cmd); # Kommenatre entfernen next if($cmd=~/^\s*#/); # Error wenn eine Unbekannter Aufruf kommt: die("CMD:$cmd FILE:$file LINE:$. Not implemented!") unless exists $funktions{$cmd}; $funktions{$cmd}->(); } close($fh); ############################## sub do_default { print "DOING DEFAULT\n" } sub do_sub1 { print "DOING SUB1\n" } sub do_sub2 { print "DOING SUB2\n" } sub do_sub3 { print "DOING SUB3\n" }
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
#!/usr/bin/perl use strict; use warnings; open(my $fh, '<', $file) or die( "ERROR OPEN $file ($!)\n" ); while(my $cmd=<$fh>) { chomp($cmd); # Kommenatre entfernen next if($cmd=~/^\s*#/); my $fref=main->can($cmd); # Error wenn eine Unbekannter Aufruf kommt: die("CMD:$cmd FILE:$file LINE:$. Not implemented!") unless $fref; $fref->(); } close($fh); ############################## sub do_default { print "DOING DEFAULT\n" } sub do_sub1 { print "DOING SUB1\n" } sub do_sub2 { print "DOING SUB2\n" } sub do_sub3 { print "DOING SUB3\n" }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/usr/bin/perl use strict; use warnings; open(my $fh, '<', $file) or die( "ERROR OPEN $file ($!)\n" ); while(my $cmd=<$fh>) { chomp($cmd); # Kommenatre entfernen next if($cmd=~/^\s*#/); { no strict 'refs'; &$cmd(); } } close($fh); ############################## sub do_default { print "DOING DEFAULT\n" } sub do_sub1 { print "DOING SUB1\n" } sub do_sub2 { print "DOING SUB2\n" } sub do_sub3 { print "DOING SUB3\n" }