Leser: 18
1 2 3 4 5 6 7
my $val1 = 1223; my $val2 = 2344; my $oper = "<="; if (val1 $oper $val2) { # Etwas machen }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
my %cmds=( '<=' => sub{ $_[0] <= $_[1] }, '==' => sub{ $_[0] == $_[1] }, '>=' => sub{ $_[0] >= $_[1] }, 'or' => sub{ $_[0] or $_[1] }, 'and' => sub{ $_[0] and $_[1] }, ); my $cmd='<='; my $param1=1; my $param2=2; if(exists($cmds{$cmd})) { if($cmds{$cmd}->($param1,$param2)) { print "$param1 ist $cmd $param2\n"; } else { print "$param1 ist nicht $cmd $param2\n"; } } else { warn(qq(UNKOWN COMMAND "$cmd"!)); }