9 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
%packets_processors = (
...,
"0110" => \&skill_failed,
"0114" => \&skill_used,
"01DE" => \&skill_used,
"0117" => \&skill_used_on_coordinates,
...
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ cat call_function_by_name.pl
use strict;
sub foo {
my $arg = shift;
print "You called foo($arg)\n";
}
my $bar = 'foo';
{
no strict 'refs';
&$bar(5);
}
$ perl call_function_by_name.pl
You called foo(5)
1
2
3
4
5
6
7
8
9
10
11
my %dispatch = (
1 => 'doOne',
2 => 'doTwo',
3 => 'doThree',
);
my $action = 1;
my $class = "XYZDASDF";
my $object = $class->new();
if (exists $dispatch{$action}) {
$object->$dispatch{$action};
}
1
2
3
4
5
6
7
8
9
10
my %dispatch = (
1 => \&XYDFASDF::doOne,
2 => \&XYDFASDF::doTwo,
3 => \&XYDFASDF::doThree,
);
my $action = 2;
my $object = XYDFASDF->new();
if (exists $dispatch{$action}) {
$dispatch{$action}->($object);
}
1
2
3
my $coderef = $object->can("gewuenschte_methode");
# oder my $coderef = $dispatch{...};
$object->$coderef(@args);
1
2
3
4
5
my $inst = child->new();
my %foo = (0110 => 'decode',a=>'Hallo ',b=>'Welt!!!');
my $bar = $inst->can('decode');
$inst->$bar(211,'hallo','xg',\%foo);
1
2
3
4
5
6
7
8
9
10
$ perl -wle'
sub child::decode {
print "decode(@_)"
}
my %foo = (0110 => "decode",a=>"Hallo ",b=>"Welt!!!");
my $inst = bless {}, "child";
my $bar = $inst->can("decode");
$inst->$bar(211,"hallo","xg",\%foo);
'
decode(child=HASH(0x813c8a4) 211 hallo xg HASH(0x813c9a0))
9 Einträge, 1 Seite |