變體1:
#!/usr/bin/perl
my $command=join(' ',@ARGV);
if ($command eq 'aviator') { &aviator; }
elsif ($command eq 'aviator debug' or $command eq 'debug aviator') { &aviator_debug; }
elsif ($command eq 'admin debug' or $command eq 'debug admin') { &admin_debug; }
elsif ($command eq 'admin') { &admin; }
else {print "invalid option ".$command."\n";exit;}
變體2:
#!/usr/bin/perl
if (grep /^aviator$/, @ARGV) {
if (grep /^debug$/, @ARGV) { &aviator_debug; }
else { &aviator; }
} elsif (grep /^admin$/, @ARGV) {
if (grep /^debug$/, @ARGV) { &admin_debug; }
else { &admin; }
} else { print "invalid option ".join(' ',@ARGV)."\n";exit;}
exit;
變體3:
#!/usr/bin/perl
use Switch;
switch (join ' ',@ARGV) {
case 'admin' { &admin();}
case 'admin debug' { &admin_debug; }
case 'debug admin' { &admin_debug; }
case 'aviator' { &aviator; }
case 'aviator debug' { &aviator_debug; }
case 'debug aviator' { &aviator_debug; }
case /.*/ { print "invalid option ".join(' ',@ARGV)."\n";exit; }
}
什麼會發生在參數之間的無限空格.. – Rajeev 2012-04-25 10:54:51
@ARGV沒有空格。無限空間自動從中刪除 – askovpen 2012-04-25 10:57:47
如何管理調試或調試管理員照顧與這種case.which是有效的.... – Rajeev 2012-04-25 11:17:14