Thread Code in Hash dynamisch erweitern (8 answers)
Opened by bianca at 2012-07-22 19:19

AndiE
 2012-07-22 20:34
#160133 #160133
User since
2010-10-24
65 articles
BenutzerIn
[default_avatar]
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/perl
use strict;
use warnings;

my %test = (
code => sub {
my $input = shift;
if ($input eq 'h')
{ return 'hallo'; }
},
);

$test{code1}= sub { my $input=shift; if ($input eq 's') { return 'sonne'; } };

my $foo = $test{code}->('h');
print "$foo\n"; # hallo erwartet
$foo = $test{code1}->('s');
print "$foo\n"; # sonne erwartet


Das funktioniert.

View full thread Code in Hash dynamisch erweitern