另一個有趣的perl function(MUSH)
######################sub AnalyzeCommand {
my ($sText) = @_;
my $a = 0;
my $match = "#IF\\(([^#]*)\\s+([^#]*)\\s+([^#]*)\\)\\{([^{}]*)\\}(\\{([^{}]*)\\})?";
while (1) {
$a++;
if ($sText =~ /$match/) {
my ($left, $compare, $right, $cmd, $cmd2) = ($1, $2, $3, $4, $6);
if ($compare eq "<") {
if (GetVariable($left) < $right) {
$sText =~ s/$match/$4/;
}
else {
$sText =~ s/$match/$cmd2/;
}
}
elsif ($compare eq ">") {
if (GetVariable($left) > $right) {
$sText =~ s/$match/$4/;
}
else {
$sText =~ s/$match/$cmd2/;
}
}
elsif ($compare eq "=") {
if (GetVariable($left) == $right) {
$sText =~ s/$match/$4/;
}
else {
$sText =~ s/$match/$cmd2/;
}
}
elsif ($compare eq ">=") {
if (GetVariable($left) >= $right) {
$sText =~ s/$match/$4/;
}
else {
$sText =~ s/$match/$cmd2/;
}
}
elsif ($compare eq "<=") {
if (GetVariable($left) <= $right) {
$sText =~ s/$match/$4/;
}
else {
$sText =~ s/$match/$cmd2/;
}
}
}
else {
$sText =~ s/[{}]//g;
last;
}
}
my @splitedCommand = split(/;/, $sText);
for my $index (0 .. $#splitedCommand) {
my $command = $splitedCommand[$index];
if ($command =~ /^#(\d+)\s+(.*)$/)
# --------------------------------------------
# Command: #3 fight bonze %i
# Send: fight bonze
# fight bonze 2
# fight bonze 3
# --------------------------------------------
{
my ($counts, $cmd) = ($1, $2);
for (my $i = 1 ; $i <= $counts ; $i++) {
my $curCmd = $cmd;
$curCmd =~ s/\%i/$i/;
AnalyzeCommand($curCmd);
}
}
elsif ($command =~ /^#dis$/)
# --------------------------------------------
# Command: #dis
# For Disconnect;
# --------------------------------------------
{
Disconnect();
}
elsif ($command =~ /^#wa\s+(\d+)$/)
# --------------------------------------------
# Command: #wa 2000
# Will send command after 2 second
# --------------------------------------------
{
my $second = $1 / 1000;
my $cmd = join ';', @splitedCommand[ ($index + 1) .. $#splitedCommand ];
#$world->Note($cmd);
#$world->Note("$priorCmd,$second,$cmd");
$second = 0.1 if ($second < 0.1);
$second = 86399 if ($second > 86399);
DoAfterSpecial($second, "AnalyzeCommand(\"$cmd\")", "12");
last;
}
#elsif($command =~ /^set (\w+)=(.+)/)
## --------------------------------------------
## Command: #set var=value
## Will set a variable to value
## --------------------------------------------
#{
# if(SetVariable($1,$2) == 0){
# Note("Set $1 to $2");
# }else{
# Note("Can not set $1 to $2");
# }
#}
else {
Execute($command);
}
}
}在mush perl script 中不能加入中文.
so 沒寫什麼注釋...ttk_13
[ 本帖最后由 vase 于 2010-1-19 01:22 AM 编辑 ] 不错! 这是天书吗? 请问楼主实现了zmud到mush的快速转换了吗? 晕,挖了个历史幽久的坟.......楼主人还在不啊 看不懂...
页:
[1]