my @array = qw /One Two Three/;
my $var = 2;
print $array[$var], "\n";
####
my %hash = ( 1 => One, 2 => Two, 3 => Three);
my $var = 2;
print "$hash{$var}\n";
##
##
my ($oper, $rest) = shift, join ' ', @_;
my $stop = 'stop';
my $force_stop = 'force_stop';
# ...
if ($oper eq $stop) {
run_stop ($rest);
cleanup();
}
elsif ($oper eq $force_stop) {
run_force_stop ($rest);
cleanup();
}
elsif ($oper eq 'start') {
run_start ($rest);
}
elsif ($oper eq 'force_start') {
run_stop ($rest);
cleanup();
run_start ($rest);
}
...
else {
die "Unknown operation: $oper \n";
}
##
##
my %dispatch_table = (
stop => sub {run_stop($rest); cleanup();},
force_stop => sub {run_force_stop($rest); cleanup();},
start => /&run_start(@rest),
force_start => sub {run_stop ($rest); cleanup() ; run_start ($rest);},
);
##
##
my ($oper, $rest) = shift, join ' ', @_;
if (defined $dispatch_table{$oper}) {
$dispatch_table{$oper}->($rest);
} else {
die "Unknown operation: $oper \n";
}