getopt java_使用 Getopt::Std 的命令行开关
用傳統的 Unix 方式創建的簡單用戶界面
Unix 用戶非常熟悉基于文本的 UI 模型。設想有一個 Perl
程序,讓我們先看一下這個模型用于該程序的簡單實現。標準的 Getopt::Std
模塊簡化了命令行參數的解析。這個程序僅僅為了說明 Getopt::Std 模塊(沒有實際用途)。
請參閱本文后面的參考資料。
使用 Getopt::Std 的命令行開關
#!/usr/bin/perl -w
use strict;# always use strict, it's a good habit
use Getopt::Std;# see "perldoc Getopt::Std"
my %options;
getopts('f:hl', \%options);# read the options with getopts
# uncomment the following two lines to see what the options hash contains
#use Data::Dumper;
#print Dumper \%options;
$options{h} && usage();# the -h switch
# use the -f switch, if it's given, or use a default configuration filename
my $config_file = $options{f} || 'first.conf';
print "Configuration file is $config_file\n";
# check for the -l switch
if ($options{l})
{
system('/bin/ls -l');
}
else
{
system('/bin/ls');
}
# print out the help and exit
sub usage
{
print <
first.pl [-l] [-h] [-f FILENAME]
Lists the files in the current directory, using either /bin/ls or
/bin/ls -l. The -f switch selects a different configuration file.
The -h switch prints this help.
EOHIPPUS
exit;
}
總結
以上是生活随笔為你收集整理的getopt java_使用 Getopt::Std 的命令行开关的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 文本框内容变化_jquer
- 下一篇: p2p靠什么盈利